0

フォームを使用して編集しようとして<%= form_for @agent, :action => 'agents/update', :method => :put do |f| %>いますが、[変更を保存] をクリックすると、フォームはアクションへの PUT ではなく GET リクエストとして送信されますupdate

私はresources :agents自分のroutes.rbファイルに持っています。

agents_controller.rb表示および更新アクションには次のものがあります。

def show
@agent = Agent.find(params[:id])
@subscription = @agent.subscription
end

def edit
@agent = Agent.find(params[:id])
@subscription = @agent.subscription
end

def update
@agent = Agent.find(params[:id])
@subscription = @agent.subscription
@agent.update_attributes(:agent)
end

標準の編集フォームが機能しないのはかなり憂鬱です。助けていただければ幸いです。

編集

agents/edit.html.erb

<%= form_for @agent do |f| %>

  <ul>
    <% for message in @agent.errors.full_messages %>
        <li><%= message %></li>
    <% end %>
  </ul>


<div class="control-group">
  <label class="control-label" style="width:200px;margin-right:20px"><strong>First name</strong></label>
  <div class="controls">
    <%= f.text_field :first_name, :placeholder => 'First name', :class => '', :style => '' %>
  </div>
</div>
<div class="control-group">
  <label class="control-label" style="width:200px;margin-right:20px"><strong>Last name</strong></label>
  <div class="controls">
    <%= f.text_field :last_name, :placeholder => 'Last name', :class => '', :style => '' %>
  </div>
</div>
    <div class="control-group">
      <label class="control-label" style="width:200px;margin-right:20px"><strong>Email</strong></label>
      <div class="controls">
        <%= f.text_field :email, :placeholder => 'Your email', :class => '', :style => '' %>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" style="width:200px;margin-right:20px"><strong>Phone</strong></label>
      <div class="controls">
        <%= f.text_field :phone, :placeholder => 'Your phone number', :class => '', :style => '' %>
      </div>
    </div>


<div class="form-actions">
  <%= f.submit "Save Changes", :class => 'btn btn-success' %>
  <%= link_to 'Cancel', leads_path, :class => 'btn' %>
</div>

<% end %>
4

2 に答える 2

2

このような単純なフォームにメソッドやアクションを提供する必要はありません。シンプルな

<% form_for @agent do |f| %>

あなたをすべきです。あなたはそれを試しましたか?競合する可能性があるページに他のフォームはありますか? もしそうなら、最初にそれらの他のフォームを削除してみて、それがどうなるかを見てください.

于 2013-06-24T21:56:04.127 に答える
0

修正しました。この投稿では、まったく同じ問題が取り上げられています: HTML <form> タグにより、Rails フォームが POST 要求ではなく GET を送信する

GET リクエストは、Twitter ブートストラップ スタイリング クラス「form-horizo​​ntal」を追加するためにそこにあった Rails フォームの周りのフォーム タグによって引き起こされています。余分なフォーム タグを削除すると、正常に動作します。

于 2013-06-24T23:36:16.040 に答える