I just got to the part where I’m creating the timeline class and i’m trying to implement ActiveModel Naming, but it’s not working. I get the same “to_partial_path” error. When I create the “to_partial_path” method and specify a partial, it works as expected and I’m able to continue with the workshop.
I’m going to continue using the to_partial_path method, but I’d really like to get the ActiveModel naming thing working.
Here’s my code:
app/models/timeline.rb
class Timeline
extend ActiveModel::Naming
def initialize(user)
@user = user
end
end
I saw another thread in here where they had to use ActiveModel::Conversion, but that didn’t work for me either.
The only thing that worked for me involves removing the ActiveModel::Naming extension and using this instead.
I got this to work with include ActiveModel::Model instead of extend ActiveModel::Naming According the the API docs, this includes more than just naming.
Is this okay to do? I’m not quite sure what the pros and cons are here.
For Rails 4 work that involves what you’re trying to do, it’s best to use ActiveModel::Model. It’s now best practice to do so.
It gives you :naming, :conversion, and essentially all the common things from ActiveModel required for robust classes dealing with Rails without necessarily being attached to anything that’ll be written in a database.