user100051
user100051

Reputation:

Rails issue with "route matching"

I'm getting the following error when loading this URL: localhost:3000/groups/5/post/new

No route matches [GET] "/groups/5/post/new"

I am trying to create a new "post" for a specific group. Here is my Post controllers "new" action:

  def new
    @group = Group.find(params[:group_id])
    @post = Post.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @post }
    end
  end

I have my routes orginized as so:

resources :groups do
  resources :posts do
    resources :comments
  end
end

Does anyone see anything that may be causing this?

Thank you.

Upvotes: 0

Views: 57

Answers (2)

Ethan Hayon
Ethan Hayon

Reputation: 346

Using that nested resource, shouldn't the path be?: /groups/5/posts/new (note the plural posts)

Upvotes: 0

xdazz
xdazz

Reputation: 160943

localhost:3000/groups/5/post/new

Should be

localhost:3000/groups/5/posts/new

Upvotes: 5

Related Questions