Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: form_for ignoring setting method

A user has the ability to edit their credit card information, like so:

CreditCardsController:

class CreditCardsController < ApplicationController
    before_filter :authenticate_user!
    respond_to :js

    def edit
      @cc = current_user.credit_cards.where(:id => params[:id]).first
      respond_with @cc
  end

end

_form.html.erb:

<%= form_for @cc, :remote => true, :html => { :method => :put } do |f| %>
    <div id="cancel-subscription" class="modal-content">
        <div class="header dotted-border">
            <h2>Billing Information</h2>
            <p>Edit the fields below to update your information</p>
        </div>
        <div class="content dotted-border">
            <h2>Credit Card</h2>
        </div>
    </div>
<% end %>

For some reason the form_foris ignorning the :method option even if I leave it off. It keeps getting set to post. That is not correct since I am editing/updating a CC entry. Anyone else run into this issue?

like image 671
dennismonsewicz Avatar asked Jan 22 '26 07:01

dennismonsewicz


1 Answers

Just adding

 :html => { :method => put }

will not work, because form_for generate _methode hidden element with form on update and delete.

just using

 :method => "put"

in form may work

like image 135
maximus ツ Avatar answered Jan 24 '26 17:01

maximus ツ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!