I have a form that needs to update a user objects attributes.
Here are the three steps that I’ve boiled down to:
-
the action ‘new’ needs to provide the form with an object to manipulate
-
The form needs to know which object to collect values for
-
when the form is submitted it needs to send these params to a function that updates the user object
If all this is kosher here’s what I’ve done to try and make this happen.
Within the ‘new’ action I’ve attempted to provide the user object like so:
@current_user = current_user
Then, in the view this is what the form looks like:
<%= form_for (@current_user) do |f| %>
<%= f.label :target_bf_pct %>
<%= f.text_field :target_bf_pct %>
<%= f.label :activity_factor %>
<%= options_for_select([['Sedentary (Desk Job)', 1.2],
['Light Activity (1-3 day a week)', 1.35],
['Moderate Activity (3-5 days a week)', 1.55],
['Very Active ( 6-7 days a week)', 1.75],
['Extremely Active (Atheletic Endurance)', 1.95]])
%>
<%# f.submit "Post", class:"btn btn-large btn-primary" %>
<% end %>
The error I’m getting at this point is this:
undefined method `user_path' for #<#<Class:0x007fd943d00d08>:0x007fd944e5b6c0>
which is referring to the forms @current_user object that’s supposed to correspond to the @current_user instance within the new action…
Important note:
-
I’m using devise for my sessions controller to create new users and handle sessions.
-
I don’t believe that my use of the form helper options_for_select is being used properly since I’ve yet to assign it a value it’s supposed to represent once selected like "activity_factor"
This is not a joke.
will work, but, for example:
will not. With space you’re on the way to do mistakes like that.
The second one. Your environment doesn’t know user_path
Add to routes.rb (even if devise’s statements exist):