SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    0 Post(s)
    0 Thread(s)

    Getting Unknown Action in Chapter 10's Tags example


    I am trying to solve a mystery for the last two days. I am following the Simply Rails 2 book and I'm in chapter 10's Tags example. I have finished all the coding so the stories shows the available tags, but when I click on the tag link to show stories that share the same tag, I get the following error on the browser:

    Unknown action

    No action responded to rails. Actions: show

    I doubled checked the following places:

    1) in my routes.rb config file, there is only one instance of map.resources with tag:
    map.resources :tags

    2) rake routes command shows that I have the following:
    tags GET /tags(.:format) {:action=>"index", :controller=>"tags"}
    POST /tags(.:format) {:action=>"create", :controller=>"tags"}
    new_tag GET /tags/new(.:format) {:action=>"new", :controller=>"tags"}
    edit_tag GET /tags/:id/edit(.:format) {:action=>"edit", :controller=>"tags"}
    tag GET /tags/:id(.:format) {:action=>"show", :controller=>"tags"}
    PUT /tags/:id(.:format) {:action=>"update", :controller=>"tags"}
    DELETE /tags/:id(.:format) {:action=>"destroy", :controller=>"tags"}

    3) I have the following in my tags controller file, app/controllers/tags_controller.rb
    class TagsController < ApplicationController
    def show
    @stories = Story.find_tagged_with(params[:id])


    4) the file under the app/views/tags/show.html.rb has:
    <h2>Stories tagged with <%= params[:id] %></h2>
    <%= render artial => @stories %>

    5) I have the story's partial file in the app/views/stories/_story.html.rb
    <% div_for(story) do %>
    <h3><%= link_to, story %></h3>
    Submitted by: <%= story.user.login %> | Score: <%= story.votes_count %>
    Tags: <%= story.tag_list %>
    <% end %>

    ~~~~~ end of code snippets

    The weird thing is, if I change the url on my browser to:
    include /tags/show/rails

    then it appears to work properly, so it is as if the routing information is not picking up the show action in tags controller even though the definition exists and rake's route information appears to say otherwise.

    Any suggestion is appreciated.

  2. #2
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Melbourne, Australia
    1 Post(s)
    0 Thread(s)
    Hi. Can you post the whole content of your routes.rb file? I have a suspicion that your problem is caused by the default rails routes being higher up in the file (and therefore taking precedence over) your map.resources declaration.

    If this is the case the router will first map /tags/rails to the rails action of the tags controller, not to the show action with "rails" as the parameter. Try moving your map.resources to the top of the routes.rb file.

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    0 Post(s)
    0 Thread(s)
    Louis, your suspicion was accurate. The problem went away after I moved the route line up in file.

    Thanks much.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts