尝试更新我在 Ruby on Rails 项目中发布的帖子,但没有任何反应。这真的很烦人,因为我没有收到任何错误并且似乎无法弄清楚我做错了什么。
我认为它以前有效,但是自从我第一次编写不同的操作以来,我已经在我的“提要”模型中添加了多个内容,例如展示次数和标签。不知道这是否影响了我的更新操作...
我的控制器如下所示:
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>