I have multiple fields for social networking websites where users can enter their username and it would link to their twitter, facebook, myspace account etc. My problem is how can I have it so when a user enters their username I can link to their account.
Here’s what I have and I know this is probably not correct. In my profile index.html
<%= link_to twitter_url %>
profile helper method
def twitter_url
return(self.url= "http://twitter.com/#{profile.twitter}/account")
end
In my profile controller
include ProfilesHelper
The actual field in database is called
twitter_link
How can I get the just the user username then on my part which will do the rest link to their twitter, facebook etc account page?
How is that method supposed to know what the
profileobject is without you passing it in?I’m imagining there being a
@profilevariable defined in your controller. In the view, you would have this:And in the helper, this:
Note here that you don’t need to set
self.urlor have an explicit return. This is because the method will automatically return aStringwhich is whatlink_totakes.If you want this method to be in a helper that’s available in just your
ProfileController, then why not put it insideProfileHelperso that it’s automatically included just by being related by name?