views:

19

answers:

2

I have a User model and Posts model. I want to display the posts belonging to each user,
via a URL say http://localhost:3000/my_posts/1" but Rails is reporting error saying
that no matching route exits for
http://localhost:3000/my_posts/1.

Rails looks at the complete url : "http://localhost:3000/my_posts/1" as a route , but my
intend is like "http://localhost:3000/my_posts/" should be taken as url route and '1' should be taken has the params:id in this case it represents the User_id.
I have the route match
"/my_posts" => "user#view_posts".

The action routine view_posts of user is working fine when triggered through
"http://localhost:3000/users/1"
here in takes 1 as params id and /user as route.
And also i'm able to display that particular user's posts in the "/user" route by
rendering the partial
<% render 'view_posts %>

I'm Using Rails version 3.

A: 
map.connect 'my_posts', :controller => ..., :action => ...
Nikita Rybak
Hi Nikita I'm using rails version 3 and i have the following route set :- match "/my_posts" => "user#view_posts". But my question is how do I pass a params id to that controller's action.
Saran
Nikita Rybak
+1  A: 
match "/my_posts/:id", :to => "user#view_posts"
Laz