Reputation: 2174
I have information listed in a model, and i'm having trouble listing that information on a view that i have.
The model is as so
SOURCES = {
"facebook" => "facebook",
"twitter" => "twitter",
"google-plus" => "google-plus",
"linkedin" => "linkedin",
"instagram" => "instagram",
"youtube" => "youtube",
"blog" => "rss",
"pinterest" => "pinterest"
}.freeze
def icon_name
SOURCES[source]
end
On my view I had
= f.input :source, collection: ["twitter", "facebook", "google-plus", "linkedin", "instagram", "youtube", "rss", "pinterest"], prompt: "Select social property"
But i'm trying to just pull from either the sources or the icon name from the model. (in attempts to DRY up the code and such) (the models name is social_link.rb )
I've tried
= f.input :source, collection: [@social_link.icon_name], prompt: "Select social property"
But...i'm not able to get anywhere with this. Am I missing something? Do I need to use my controller? (i'm not at the moment)
Thanks much!
Upvotes: 0
Views: 24
Reputation: 15515
To use the values of the SOURCES
constant of your model:
= f.input :source, collection: SocialLink::SOURCES.values, prompt: "Select social property"
And don't forget to add some validation to your model!
Edit: not sure how you want to use icon_name
here.
Upvotes: 1