Hello, i have table AuditLog with fields including: audited_id |
audited_type
That results in data like:
108 | Photo
303 | Comment
What I want to do is create a link to the item, so for the example
above:
<a href="/photos/108">here is the photo</a>
I'm trying to use a polymorphic_path but am getting an error:
"undefined method `model_name' for Fixnum:Class"
When using:
<%= link_to 'Here she is', polymorphic_path([audited_id,
audited_type]) %>
Ideas? Thanks
you have to pass 2 objects to polymorphic_path(parent_model_object, object) , audited_id is a number , that is what Fixnum:Class means, polymorphic path assembles a helper method like this,
polumorphic_path(audit.auditable, audit ) =====> takes the first object passed as audit.auditable, because auditable is the alias for the parent model, so in your case is trying to get the model out of that first parameter which is a number, when it should be instance of Photo or comment, so it can create this => photo_audit_path , you see? this happens if you pass an instance of the parent model and then the instance of the polymorphic model.
you are passing a number and a string, auditer_id is a number and audited_type is a string.
Interesting, so what I have available is:
audited_id = 33
audited_type = Photo
So using the polymorphic_path how do I take what I have from the DB
AuditLog record and pass an instance of Photo?
<%= link_to 'Click to See It!', polymorphic_path([record.audited_id,
record.audited_type]) %>
?
Maybe there is a better way to make the link : "/photos/33" based on
the data I have?
Something like /<%audited_type.pluralize%>/<%audited_id%>
Any suggestions? Or is polymorphic_path the right way to go?
Thanks,
Brett
hum , i thought i was clear… oh well
polymorphic_path(audit.auditable, audit )
Ah shoot, I think the reason it wasn't working is I had some records
in the table that were empty for the polymorphic assoc... I guess it
fails if it's blank.. thank you!