I have a profile model that has a user state model (emotional state) -
What I would like to do is give the user object the ability to change
their state through the profile model. The code that I've written is
below. I'm receiving "NoMethodError - undefined method 'state_id' for
#<Profile:Obj %>" even though, they're associated with each other.
Profile.rb
belongs_to :states
State.rb
has_many :profiles
_state_form.html.erb
<%= simple_form_for @user, url: current_user, html: {multipart: true},
layout: :horizontal do |f| %>
<%= f.simple_fields_for :profile do |n| %>
<%= n.label :state_id, 'Select a state' %>
<%= n.collection_select :state_id, State.all, :id, :name %>
<%= f.submit 'Change State', class: 'btn btn-info-outline' %>
<% end %>
<% end %>
I seeded the names of the states into the db table. Because, I don't
want anyone altering the records to add their own.
<%= render 'users/shared/state_form' %>
Maybe, I'm missing something, but this approach seems to work without
issue for categories.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/33864495c9bc99a4e62a62dfd435f649%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment