I’m modeling my User model and adding profile attributes.
I’m looking to add a set of social URLs for the user, starting with about 3 or 4 options and possibly growing to more than 15. It would be very easy for me to just create a separate attribute on the User model for every URL, and then run through them all separately for the profile page. Although this seems like it might be redundant, would this be inappropriate or should I go ahead since the attributes just store a simple string?
If I shouldn’t load them all onto the User model:
What would be the best way to go about doing this with a separate model? Any how would I be able to grab all the social urls a user has created in an @social_urls array?
I’m also looking to associate a specific thumbnail image with each website URL to be displayed with the @social_urls.each do block. I’m confused on how I would call dynamically to the correct image.
Thanks so much for any help or insight.
Edit: would this work to attach a html class with the social site name? and then create a thumbnail using css?
# In erb or (better) a helper
<% User::SOCIAL_SYSTEMS.each do |social_system|
url = @user.send(social_system)
if url %>
<p><a href="<%= url %>" class="<%=User::SOCIAL_SYSTEM_NAMES[social_system]%>"><%=
User::SOCIAL_SYSTEM_NAMES[social_system] %></a></p>
<% end
end %>
Creating additional attributes on the User model for independent facts (the social urls) is fine.
Or you could have another two models just for social urls with structure
But no need for the additional complexity of the two extra tables unless you really see a value.
Re:
You can (and should) create helper methods for your User model. Eg, you can have the names of the social attributes as a CONST array and then use #send to retrieve all their values.
Added The tradeoffs between the two styles (either using the User model or creating two additional models)–
In terms of space, db storage is so cheap that it makes no difference. — Ie the User model style is sparser storage of the data.
I think I would focus on the main part of my app and just use the User model. Simpler and sweeter.
Added Re comments:
For the thumbnail, paperclip or similar is the way to go. — It does create an additional model and table, but the plugin handles all the details.
For showing the urls, you’d use a helper or two. Eg
Added ps
If you need to store more than one fact per social system (eg url for the profile from the social system plus the person’s latest score from the social system), then I would go for the additional tables. But if you only need a single fact (eg the person’s profile url), then adding to the user model is fine. (imho)