I'm using rails 3.2.11 and ruby 1.9.3. I have a slow page and I know I have many ways to optimize it. Currently I am focused on the method update_attributes.
Here is my code:
def create
@user = current_user
@demo = @user.demos.new
race_ethnicity_response = []
params[:race_ethnicity_response].each do |response, value|
race_ethnicity_response << response if value != '0'
end
params[:demo][:race_ethnicity_response] = race_ethnicity_response.join(', ')[0, 254]
@demo.update_attributes(params[:demo])
end
Or should I use something like build and save or create?
@demo = @user.demos.build
...
@demo.save!
Or
@users.demos.create!(params[demo])
I am curious which is faster. I know if it save 2ms then I should use the one which is more code correct/readable.
Aucun commentaire:
Enregistrer un commentaire