I have problem with strong params in Ruby on Rails 4
.
I have 3 models Entity
, user
, user_entity
.
User_entity
ties together entity
and user
with has_many :through
association.
Here is code that works perfectly!
/views/user_entity/show.html.erb
<p>
<strong>User:</strong>
<%= @user_entity.user_id %>
</p>
And here when I modify it it doesn't!
<p>
<strong>User:</strong>
<%= @user_entity.user.name %>
</p>
Error I get is this:
undefined method `user' for # Extracted source (around line #433):
else match = match_attribute_method?(method.to_s) match ? attribute_missing(match, *args, &block) : super end end
I think it is because of strong params
not allowing me to access data from user
controller, but i have no idea how to whitelist that data to user_entity
model.
Please help.
/models/entity.rb
class Entity < ActiveRecord::Base
accepts_nested_attributes_for :user_entities
has_many :user_entities
has_many :users, :through => :user_entities
end
/models/user.rb
class User < ActiveRecord::Base
accepts_nested_attributes_for :user_entities
has_many :user_entities
has_many :entities, :through => :user_entities
end
/models/user_entity.rb
class User_entity < ActiveRecord::Base
belongs_to :entities
belongs_to :users
end