我正在使用 Feedjirra gem 构建一个 RSS 提要,并带有将提要条目保存到列表中的选项。当我尝试编辑保存的条目以添加标签或删除条目时,我收到一个错误,即即使我使用的是列表全局变量,它也找不到列表 ID。
我没有嵌套我保存的条目,所以我也可能遇到路由错误。我还设置了手动将链接输入列表页面并将它们放在单独的控制器下的选项。我可以编辑和删除我手动输入的链接,但不能从提要中删除。
首先,错误:
Started GET "/entries/9/edit" for 127.0.0.1 at 2015-10-19 20:58:40 -0700
Processing by EntriesController#edit as HTML
Parameters: {"id"=>"9"}
Completed 404 Not Found in 1ms
ActiveRecord::RecordNotFound (Couldn't find List without an ID):
app/controllers/entries_controller.rb:22:in `edit'
这是我保存条目的提要页面:
<% @feeds.each do |feed| %>
<p class="feed_url">
<%= link_to feed.url, feed %>
<%= link_to "Edit", edit_feed_path(feed), class: "blue" %>
<%= link_to "Delete", feed_path(feed), method: :delete, data: { confirm: 'Are you sure you want to delete this feed url?' }, class: "blue" %>
</p>
<div class="entry_wrapper">
<div class="entry_box">
<% feed.entries.each do |entry| %>
<p class="entry_title"><%= sanitize link_to entry.title, entry.url %></p>
<div class="select_tag">
<%= form_tag entries_path do %>
<%= hidden_field_tag :url, entry.url %>
<%= select_tag :list, options_from_collection_for_select(@lists, :id, :name) %>
<%= submit_tag "Add To List", class: "btn" %>
<% end %>
</div>
<p class="entry_info">
<%= sanitize get_info(entry), length: 30 %>
</p>
<% end %>
这是来自提要的已保存条目的控制器:
def index
if params[:tag]
@saved_entries = SavedEntry.tagged_with(params[:tag])
@tag = params[:tag].capitalize
else
@saved_entries = SavedEntry.all
end
authorize @items
end
def create
@list = List.find(params[:list])
@saved_entry = SavedEntry.new_with_preview(url: params[:url])
@saved_entry.list = @list
@saved_entry.save
redirect_to request.referer
end
def edit
@list = List.find(params[:list_id])
@saved_entry = SavedEntry.find(params[:id])
end
def update
@saved_entry = SavedEntry.find(params[:id])
if @saved_entry.update_attributes(url: params[:url])
flash[:notice] = "You have updated the entry."
redirect_to @list
else
flash[:notice] = "There was an error. Please try again."
render :edit
end
end
def destroy
@list = List.find(params[:list_id])
@saved_entry = SavedEntry.find(params[:id])
end
这是列表显示页面:
<% @saved_entries.each do |entry| %>
<div class="list_box">
<div class="list_image"><%= image_tag(entry.image_url) %></div>
<p>
<%= link_to entry.url, entry.url, target: "_blank" %><br />
<br />
<p>
Tags: <%= raw entry.tag_list.map { |t| link_to t, tag_path(t) }.join(', ') %>
</p>
<% if current_user %>
<div class="list_edit_delete">
<small><%= link_to "Edit", edit_entry_path(entry) %></small>
<small><%= link_to "Delete", entry_path(entry), method: :delete %></small>
</div>
<% end %>
和 saved_entries edit.html.erb
<div class="lists">
<%= form_for [@list, @saved_entry] do |f| %>
<%= f.label :url, "URL", class: "" %>
<%= f.text_field :url, class: "" %><br />
<%= f.submit "Save", class: "d_button" %>
<% end %>
</div>
如果有人能理解这一点,将不胜感激。