Question

Fairly new to RoR and wondering how I might move this one line of code out of my view and into my controller. I am also using devise and a current user is logged in. Thanks in advance

profile.html.erb

 <%= @profile.calorie / 4  %>

Ive set up a method called calculate within my profiles_controller.rb like so

 helper_method :calculate

 def calculate 
  ..... 
 end 
Était-ce utile?

La solution

Just put the calculation in an instance variable in your controller and call it in your view:

<%= @new_calorie  %>

And in your controller action:

def show #or index
   @new_calorie = @profile.calorie / 4
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top