Reputation: 425
I have created a Category class:
class Category < ActiveRecord::Base
attr_accessible :name
has_many :posts
end
When I created a new object:
category = Category.new(:name => "News")
I am getting this error:
`NoMethodError: undefined method 'attr_accessible' for Category(call
'Category.connection' to establish a connection):Class ...
How can I resolve this?
Upvotes: 2
Views: 700
Reputation: 771
Below should fix also. No need to put ::Base -- you can remove it.
class Category < ActiveRecord
attr_accessor :name
has_many :posts
end
Upvotes: 0
Reputation: 943
This will fix your issue.
class Category < ActiveRecord::Base
def user_params
params.require(:name)
end
has_many :posts
end
Upvotes: 1
Reputation: 24337
You want to use attr_accessor
, not attr_accessible
.
attr_accessor is a Ruby method that defines setter and getter methods, while attr_accessible lets you whitelist ActiveRecord attributes for mass assignment.
Upvotes: 0