1

I have a collection built with a Myclass.joins().where() statement.

The problem I have is when I want to customize the text_method in:

options_from_collection_for_select(@collection,"id", custom_text_method)

My problem is that @collection items are not a instance of Myclass, but only a instance of Class.

Thanks for any hints! Markus

2 Answers 2

0

I found a solution. I just changed the name of each @collection item in the controller.

That worked for me!

0

you can define a method in specify model, for example, there are two column in user table. one is first name, the other is last name. show full name as text_method.

def full_name
  "#{self.last_name}, #{self.first_name}"
end

in options_from_collection_for_select,text_method param use full_name:

options_from_collection_for_select(collections, "id","full_name")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.