views:

21

answers:

1

Hello, sorry for my english,

I have worked in a helper to create an objects tree based in :has_many associations and it's working fine, but I have a problem with links: some objects don't have an edit action to create a link (edit_object_path object_id). How can I to know, if an object has edit action?

Regards.

A: 

Hi Ruby has a function called respond_to? that can be used to seeing if a particular class or object has a method with a certain name. The syntax is something like

User.respond_to?('name') # returns true is method name exists otherwise false
Bohdan Pohorilets