Ruby on Rails的update_attributes方法真的能有效防止SQL注入吗?
- 内容介绍
- 文章标签
- 相关推荐
本文共计173个文字,预计阅读时间需要1分钟。
update_attributes方法能否防止SQL注入?+示例:+if @user.update_attributes(params[:user])+
update_attributes是否可以防止sql注入?例:
if @user.update_attributes(params[:user]) # updated end
我知道find(),{}和[]做find:conditions,但是没有看到关于这个方法的任何信息.
是的,它确实.在内部,它只是循环遍历所有属性,设置它们的值然后调用save!def update_attributes(attributes) with_transaction_returning_status do self.attributes = attributes save end end def attributes=(new_attributes, guard_protected_attributes = true) ... attributes.each do |k, v| if k.include?("(") multi_parameter_attributes << [ k, v ] elsif respond_to?("#{k}=") send("#{k}=", v) else raise(UnknownAttributeError, "unknown attribute: #{k}") end end end
换句话说,它的作用是什么
m.update_attributes(:attr1 => "foo", :attr2 => "bar") m.attr1 = "foo" m.attr2 = "bar" m.save
本文共计173个文字,预计阅读时间需要1分钟。
update_attributes方法能否防止SQL注入?+示例:+if @user.update_attributes(params[:user])+
update_attributes是否可以防止sql注入?例:
if @user.update_attributes(params[:user]) # updated end
我知道find(),{}和[]做find:conditions,但是没有看到关于这个方法的任何信息.
是的,它确实.在内部,它只是循环遍历所有属性,设置它们的值然后调用save!def update_attributes(attributes) with_transaction_returning_status do self.attributes = attributes save end end def attributes=(new_attributes, guard_protected_attributes = true) ... attributes.each do |k, v| if k.include?("(") multi_parameter_attributes << [ k, v ] elsif respond_to?("#{k}=") send("#{k}=", v) else raise(UnknownAttributeError, "unknown attribute: #{k}") end end end
换句话说,它的作用是什么
m.update_attributes(:attr1 => "foo", :attr2 => "bar") m.attr1 = "foo" m.attr2 = "bar" m.save

