Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - ActiveAdmin - Displaying ActiveRecord object instead of text

I currently have a Rails 3.0.10 app and I made two models with simple associations: has_many, and belongs_to.

After installing the ActiveAdmin plugin and creating the corresponding Ruby resource files, I've noticed some strange behavior.

Below, you can see that "Job File" belongs_to "Ernet Clients". The associations are all working correctly, however, the display name is appearing as the actual ActiveRecord object instead of the client name.

enter image description here

This is the show view when under the "Job File" section:

enter image description here

But, if I go to view the actual client, the correct text appears:

enter image description here

There must be something going wrong in the "Job File" resource that is causing this, but I can't figure out what it could be. After googling I found this: http://groups.google.com/group/activeadmin/browse_thread/thread/2a261e070efa7bae

Within the JobFile.register file I specified the display name with this:

filter :ernet_client, :display_name_methods => :display_name

This didn't work, though, and I cycled through all of the other available names to no avail.

I looked up ActiveAdmin's dependencies and sass-rails seems to be the only one - but that is if you are using 3.1 and I'm using Rails 3.0.10.

And finally, to be sure that my associations were indeed working, I opened up the Rails console and created a job file:

job = JobFile.new
=> #<JobFile hash returned>
job.ernet_client_id = 2
=> 2
job.ernet_client.client_name
=> Target

Everything seems to be working as it should.

Anyone have any insight on to how to solve this?

like image 758
PhillipKregg Avatar asked Oct 29 '11 21:10

PhillipKregg


1 Answers

Did you try defining a to_s method on the ErnetClient model?

def to_s
  display_name
end

It looks like this is the method that is being called automatically, as if you did call to_s on one of these objects in the console you would get a similar result.

like image 111
Ryan Bigg Avatar answered Oct 21 '22 04:10

Ryan Bigg