-1

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
DanielsV
  • 892
  • 1
  • 8
  • 26

1 Answers1

0

It looks like you misspelled <%= @eser_entity.user.name %>

It should be <%= @user_entity.user.name %>

Edit:

In /models/user_entity.rb you used class User_entity for your model's class name. Class names are expect to be CamelCased:

class UserEntity < ActiveRecord::Base
  ...
end
  • Also, it is just a sample. in reality i use one work, so it won't be the solution. here is the tutorial i'm stuck at http://www.gitmatt.com/posts/5 problem is i can't use `attr_accessible` with rails 4. those strong params are making this error. At least i think so. – DanielsV May 20 '15 at 21:55