I recently converted to Rails 4 and strong params, and I'm having a hard time figuring this out.
My model looks like so:
class Message
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
validates :name, :email, :body, :presence => true
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
It's my understanding that I don't need a controller containing strong params for this model, because I'm strictly "getting" it. I'm not updating or saving it anywhere, so I don't need to permit any params to be passed through. However, to be sure, I have this controller:
class MessagesController < ApplicationController
private
def message_params
params.require(:message_params).permit(:name, :email, :body)
end
end
This throws an error:
message = Message.new
message.name = 'test'
NoMethodError: undefined method `name=' for #<Message:0x007f9d620706f0>
My model used to contain this:
attr_accessor :name, :email, :body
And it worked fine. What am I missing in my rails 4 upgrade, and what do I need to change to gain access to these attributes again?