I just installed Ruby on Rails and created a scaffold called posts
. RoR generated controllers and other required files for me.
I created a new method in posts_controller
, but I can't access it. I looked at other methods that are in the controller and looks like I need to access them by /posts/[MY POST ID]/[MY METHOD NAME]
.
Assuming I created my custom method hello
in the controller, how do i access it?
I looked at routes.rb
, but there's no configuration for it.
Updated:
I understand that I can manually configure it in routes.rb
, but how do all the other methods work? For example, I have "edit
", and "update
" methods in the "posts_controller.rb
" controller. How do those two methods work without configuring routes?
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end
I can't find a configuration that matches /posts/[0-9]/edit
pattern.
The documentation you're looking for is Rails Routing From the Outside In. Once you've read this you'll understand everything Rails does to take your request and point it at method in your controller.