我正在尝试使用表单进行编辑,<%= form_for @agent, :action => 'agents/update', :method => :put do |f| %>
但是当我单击“保存更改”时,表单将作为 GET 请求而不是 PUT 提交给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 %>