1

docs say that options_from_collection_for_select should be used following way:

options_from_collection_for_select(collection, value_method, text_method, selected = nil) 

so, in my case for example

options_from_collection_for_select(@messages,'id','title')

but i need to put more information to title, so what i tried to do was:

class Message < ActiveRecord::Base

 def proper_title
  self.name+", updated at "+self.updated_at
 end

end

and it works, but thing is i need strings internationalized and it's a bit more difficult with models than with controllers. now do i have to do model internationalization in this case or is it possible to get around somehow? thanks

1 Answer 1

1

You can still call I18n.translate() in the model. It will give you the same result as t() helper

# Message.rb
def proper_title
  I18n.translate("message.proper_title", :name => self.name, :updated_at => self.updated_at)
end

# en.yml
en:
  message:
    proper_title: "{{name}}, updated at {{updated_at}}"

# view
options_from_collection_for_select(@messages,'id','proper_title')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.