Hi all,

In a sample project, I have a nested resource called ticket, and parent
resource called project.

rake routes:
...
project_tickets GET /projects/:project_id/tickets(.:format)
{:action=>"index", :controller=>"tickets"}

POST /projects/:project_id/tickets(.:format)
{:action=>"create", :controller=>"tickets"}
...

but when I go to http://127.0.0.1:3000/projects/7/tickets/ I have this
routing error:

No route matches {:action=>"show", :controller=>"tickets",
:project_id=>nil, :id=>#<Project id: 7,
name: "bla...bla", created_at: "2011-11-29 14:39:51",
updated_at: "2011-11-29 14:39:51">}

It invokes the show action and not the index action. Why?

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Frederick Cheung at Dec 1, 2011 at 11:55 am

    On Dec 1, 11:28 am, Vogon Primo wrote:
    Hi all,

    In a sample project, I have a nested resource called ticket, and parent
    resource called project.

    rake routes:
    ...
    project_tickets GET    /projects/:project_id/tickets(.:format)
    {:action=>"index", :controller=>"tickets"}

    POST   /projects/:project_id/tickets(.:format)
    {:action=>"create", :controller=>"tickets"}
    ...

    but when I go tohttp://127.0.0.1:3000/projects/7/tickets/I have this
    routing error:

    No route matches {:action=>"show", :controller=>"tickets",
    :project_id=>nil, :id=>#<Project id: 7,
    name: "bla...bla", created_at: "2011-11-29 14:39:51",
    updated_at: "2011-11-29 14:39:51">}

    It invokes the show action and not the index action. Why?
    It's also doing weird stuff because it hasn't picked a project_id from
    the url but it has picked an id. Do you have any other routes that
    might be matching this url instead of the ones that you intended to be
    used?

    Fred
    --
    Posted viahttp://www.ruby-forum.com/.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Vogon Primo at Dec 1, 2011 at 12:15 pm

    Frederick Cheung wrote in post #1034554:
    On Dec 1, 11:28am, Vogon Primo wrote:
    POST /projects/:project_id/tickets(.:format)

    It invokes the show action and not the index action. Why?
    It's also doing weird stuff because it hasn't picked a project_id from
    the url but it has picked an id. Do you have any other routes that
    might be matching this url instead of the ones that you intended to be
    used?

    Fred
    Hi Frederick,

    I have only the standard REST routes generated by Rails, with

    MyProject::Application.routes.draw do

    get "projects/index"

    root :to=> 'projects#index'

    resources :projects do
    resources :tickets
    end

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Thiagocifani at Dec 1, 2011 at 12:22 pm
    in your path are you sending the project object as params?

    2011/12/1 Vogon Primo <lists@ruby-forum.com>
    Frederick Cheung wrote in post #1034554:
    On Dec 1, 11:28am, Vogon Primo wrote:
    POST /projects/:project_id/tickets(.:format)

    It invokes the show action and not the index action. Why?
    It's also doing weird stuff because it hasn't picked a project_id from
    the url but it has picked an id. Do you have any other routes that
    might be matching this url instead of the ones that you intended to be
    used?

    Fred
    Hi Frederick,

    I have only the standard REST routes generated by Rails, with

    MyProject::Application.routes.draw do

    get "projects/index"

    root :to=> 'projects#index'

    resources :projects do
    resources :tickets
    end

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.

    --
    thiagocifani
    http://thiagocifani.wordpress.com/
    twitter.com/thiagocifani
    del.icio.us/thiagocifani
    <http://del.icio.us/thiagocifani>

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Vogon Primo at Dec 1, 2011 at 12:48 pm

    thiagocifani wrote in post #1034560:
    in your path are you sending the project object as params?

    2011/12/1 Vogon Primo <lists@ruby-forum.com>
    root :to=> 'projects#index'
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.

    --
    thiagocifani
    http://thiagocifani.wordpress.com/
    twitter.com/thiagocifani
    del.icio.us/thiagocifani
    <http://del.icio.us/thiagocifani>
    No, I am not sending the project object as param, perhaps looking at
    tickets controller may be useful ?

    class TicketsController < ApplicationController

    before_filter :find_project, :only=>[:new,:create,:show,:index]

    def find_project

    begin
    @project = Project.find(params[:project_id])
    rescue ActiveRecord::RecordNotFound
    flash[:error]="The project you were looking for could not be
    found"
    redirect_to root_path
    end

    end

    private :find_project

    #__________________________


    def new


    @ticket = @project.tickets.build
    @title="--New Ticket for #{@project.name}"

    end


    def create

    @ticket = @project.tickets.build(params[:ticket])

    if @ticket.save
    flash[:success]="Ticket has been created"
    redirect_to [@project,@ticket]
    else
    flash[:error]="Ticket has not been created"
    render 'new'
    end


    end

    #___________________________



    def index

    @tickets = @project.tickets.all
    @title="--#{@project.name}--Tickets"

    end


    # refactor later

    def show
    begin
    @ticket = @project.tickets.find(params[:id])
    rescue ActiveRecord::RecordNotFound

    flash[:error]="The ticket you were looking for could not be
    found"
    redirect_to @project
    return
    end

    @title="--#{@project.name}--Show Ticket--#{@ticket.title}"

    end


    end

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Vogon Primo at Dec 1, 2011 at 5:29 pm

    Vogon Primo wrote in post #1034547:
    Hi all,

    In a sample project, I have a nested resource called ticket, and parent
    resource called project.

    rake routes:
    ...
    project_tickets GET /projects/:project_id/tickets(.:format)
    {:action=>"index", :controller=>"tickets"}

    POST /projects/:project_id/tickets(.:format)
    {:action=>"create", :controller=>"tickets"}
    ...

    but when I go to http://127.0.0.1:3000/projects/7/tickets/ I have this
    routing error:

    No route matches {:action=>"show", :controller=>"tickets",
    :project_id=>nil, :id=>#<Project id: 7,
    name: "bla...bla", created_at: "2011-11-29 14:39:51",
    updated_at: "2011-11-29 14:39:51">}

    It invokes the show action and not the index action. Why?
    Ok, I am sorry but, it was my error . In index.html.erb I had

    <%=link_to ticket.title,project_ticket_path(@project,@path)%>

    this, on the contrary of what is present in some online RoR examples,
    doesn't work for me. I have changed it with

    <%=link_to ticket.title,[@project,@path] %>

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 1, '11 at 11:28a
activeDec 1, '11 at 5:29p
posts6
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase