试图更新我在Ruby on Rails项目中发布的帖子,但没有任何反应。这真的很烦人,因为我没有得到任何错误,似乎无法弄清楚我做错了什么。Ruby on Rails - 编辑不工作
我认为它很有用,但自从我第一次写了不同的动作以来,我在“feed”模型中添加了多个内容,例如印象和标签。不知道这影响了我的更新动作......
我的控制器看起来是这样的:
def edit
@feed = Feed.find(params[:id])
end
def update
@feed = Feed.find(params[:id])
respond_to do |format|
if @feed.update_attributes(params[:feed])
format.html { redirect_to @feed, notice: 'Feed was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @feed.errors, status: :unprocessable_entity }
end
end
end
我饲料模型是这样的:
attr_accessible :content, :tag_list, :guid, :language, :location, :published_at, :summary, :url, :title, :user_id, :thumbnail_url, :url_to_feed, :type_of_feed
has_many :impressions, :as=>:impressionable
validates_length_of :tag_list, :maximum => 10
acts_as_taggable
我的看法是这样的:
<h1>Editing feed</h1>
<%= render 'form' %>
<%= link_to 'Show', @feed %> |
<%= link_to 'Back', feeds_path %>
____________________ form
<%= form_for(@feed) do |f| %>
<% if @feed.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@feed.errors.count, "error") %> prohibited this feed from being saved:</h2>
<ul>
<% @feed.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="field">
<%= f.label :location %><br />
<%= f.text_field :location %>
</div>
<div class="field">
<%= f.label :language %><br />
<%= f.text_field :language %>
</div>
<div class="field">
<%= f.label :tag_list, "Tags (seperated by spaces)" %><br />
<%= f.text_field :tag_list %>
</div>
<div class="actions">
<%= f.submit %>
</div>
你肯定叫你的编辑方法是什么?在提交表单后立即查看log/development.log进行调试。您会在给定的日志文件中找到控制器,操作和发送的参数。 – 2013-02-17 10:47:41
感谢Sergey提供的回复。 当我在development.log中查看时,我可以看到我的GET请求正在启动编辑页面:在2013-02-17 12:27:31 +0100开始GET“/ feeds/1/edit”for 127.0.0.1 ...“然后我有: ”Started PUT“/ feeds/1”for 127.0.0.1 at 2013-02-17 12:27:36 +0100 Processing by FeedsController#show as HTML“ – OXp1845 2013-02-17 11:18:48