title: Rails - Update a single attribute : link with custom action or form with hidden fields?
body: <p>Let's say I have a User model, with a facebook_uid field corresponding to the user's facebook id.</p>
  
  <p>I want to allow the user to unlink his facebook account. Do do so, I need to set this attribute to nil.</p>
  
  <p>I currently see 2 ways of doing this</p>
  
  <h2>First way : create a custom action and link to it</h2>
  
  <pre><code># app/controllers/users_controller.rb
  def unlink_facebook_account
    @user = User.find params[:id]
    # Authorization checks go here
    @user.facebook_uid = nil
    @user.save
    # Redirection go here
  end
  
  # config/routes.rb
  ressources :users do
    get 'unlink_fb', :on =&gt; :member, :as =&gt; unlink_fb
  end 
  
  # in a view
  = link_to "Unlink your facebook account", unlink_fb_path(@user)
  </code></pre>
  
  <h2>Second way : create a form to the existing update action</h2>
  
  <pre><code># app/views/user/_unlink_fb_form.html.haml
  = form_for @user, :method =&gt; "post" do |f|
    = f.hidden_field :facebook_uid, :value =&gt; nil
    = f.submit "Unlink Facebook account"
  </code></pre>
  
  <p>I'm not a big fan of either way. </p>
  
  <ul>
  <li><p>In the first one, I have to add a new action for something that the update controller already can do.</p></li>
  <li><p>In the second one, I cannot set the facebook_uid to nil without customizing the update action, and I cannot have a link instead of a button without adding some javascript.</p></li>
  </ul>
  
  <p>Still, what would you recommend as the best and most elegant solution for this context? Did I miss a third alternative?</p>
  
  <h1>Solution (suggested by Abdullah Jibaly)</h1>
  
  <p>Use a link to the update action, with the attribute to update as parameters ; and handle the case when the attribute is set to 0</p>
  
  <pre><code>= link_to "Unlink your facebook account", 
            user_path(@user, 
                      :user =&gt; { :facebook_uid =&gt; 0}),
            :method =&gt; :put, 
            :confirm =&gt; "Are you sure?"
  </code></pre>