Adding "linked accounts" (e.g., Twitter, Facebook) to a Rails 3 website
This isn't a question about how to use Twitter or Facebook API, but a simpler one about how to keep the databases in sync. What I want to do is to create a NEW linked account, and then attach that to the current user. I KNOW that my code currently is nonfunctional:
On the Edit Profile page
<%= f.label :account %> <i>(link another account to this profile)</i><br />
<% form_for @user.linked_accounts do |f| %>
<%= f.text_field :username %>
<%= f.collection_select :service, User::POSSIBLE_SERVICES, :to_s, :to_s,
:include_blank => true
%>
<%= f.submit %>
<% end %>
How do I get it to submit into a devise database? It's definitely the " form_for @user.linked_accounts " I need to fix. I changed it to @user and I get a no-method erro开发者_运维问答r because :service is only defined in a linked account. I think that what I need to do is to create a new linked account, and then do the form_for @user.new_account.
The error I receive is:
SQLite3::SQLException: no such column: linked_accounts.user_id: SELECT "linked_accounts".* FROM "linked_accounts" WHERE ("linked_accounts".user_id = 1)
There is a railscast that deals with this. It uses an authorisations table which belongs_to the user table so you can add twitter, facebook etc... to the user
The cast is over 2 episodes and uses omniauth which is a really neat solution. You can find them here http://railscasts.com/episodes/235-omniauth-part-1 http://railscasts.com/episodes/236-omniauth-part-2
if i correctly understand your problem it's may be a solution for you to :
- create a new model to contain social network information
- use nested model to allow adding social via the edit user form
And that's it
精彩评论