I’m building an RSS feed using the Feedjirra gem with the option to save feed entries into a list. When I try to edit the saved entries to add tags, or delete an entry, I get an error that it cannot find the list id even though I am using a list global variable.
I have not nested my saved entries so I may also have a routing error. I also had set up the option to manually enter links into the lists page and put them under a separate controller. I can edit and delete links I've manually entered just fine, but not from the feed.
First of all, the error:
Started GET "/entries/9/edit" for 127.0.0.1 at 2015-10-19 20:58:40 -0700Processing by EntriesController#edit as HTMLParameters: {"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'
Here is the feed page where I’m saving the entries:
<% @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 %>
Here is the controller for the saved entries from the feed:
def index if params[:tag] @saved_entries = SavedEntry.tagged_with(params[:tag]) @tag = params[:tag].capitalizeelse @saved_entries = SavedEntry.allend authorize @itemsenddef 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.refererenddef edit @list = List.find(params[:list_id]) @saved_entry = SavedEntry.find(params[:id])enddef 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 endend def destroy @list = List.find(params[:list_id]) @saved_entry = SavedEntry.find(params[:id])end
Here is the list show page:
<% @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 %>
And 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>
If anyone can make senses of this, it would be greatly appreciated.