找不到已保存的RSS条目的列表ID

时间:2015-10-20 04:26:42

标签: ruby-on-rails ruby rss feeds feedjira

我正在使用Feedjirra gem构建RSS提要,并选择将提要条目保存到列表中。当我尝试编辑保存的条目以添加标签或删除条目时,即使我使用列表全局变量,也会收到无法找到列表ID的错误。

我没有嵌套我保存的条目,所以我可能也有路由错误。我还设置了手动输入链接到列表页面并将它们放在单独的控制器下的选项。我可以编辑和删除我手动输入的链接,但不是来自Feed。

首先,错误:

var QuestionId ;
$(document).ready(function () {

    var url = window.location.href;
    var params = url.split('?');
    var str1 = params[1].replace ( /[^\d.]/g, '' );
    QuestionId=parseInt(str1, 10);
    $('#QuestionAnswers').jtable({
        title: 'Question Answers',
        actions: {
            listAction: 'CRUDController?action=list',
            createAction:'CRUDController?action=create',
            updateAction: 'CRUDController?action=update',
            deleteAction: 'CRUDController?action=delete'
        },
        fields: {
          OptionId: {
                title:'S.NO',
                key: true,
                list: true,
                create:true
            },
           OptionValue: {
                title: 'OPTION',
                width: '30%',
                edit:true
            }    
        }
    });
    $('#QuestionAnswers').jtable('load');

});

以下是我要保存条目的Feed页面:

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'

以下是来自Feed的已保存条目的控制器:

<% @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

已保存条目edit.html.erb

<% @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 %>

如果有人能够理解这一点,我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

@list = List.find(params[:list_id])

params[:list_id]必须未定义,即nil,这会引发此错误。我没有看到你把它传递给

<small><%= link_to "Edit", edit_entry_path(entry) %></small>