You should be doing this in the model, not controller.
If you want to do this everytime the user record is saved, then define a
before_save callback in your model and add this in the method

def udpate_result
  self.result = self.height*self.weight
end

Note: You will have to convert height and weight to integer/float if you
have not defined those columns as just string in the database.


Chirag
http://sumeruonrails.com



2011/8/18 Cássio Godinho <cassiopgodi...@gmail.com>

> Lets supose I have a User table, and on this table I have height, weight
> and result rows.
> In a form I input height and weight values and want to multiply those two
> values and store on the resulta row on database. I was trying something like
> that
>
>       def criar
>         @user = User.new(params[:user])
>         @result = @user.height * @user.weight
>         @user.result = @result
>
> But its not working, what am i doing wrong?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to