开发者

adding a method to an existing controller

I'm pretty 开发者_C百科new to rails, and I'm hoping you can help me understand how the following works.

At present I have a controller named projects (projects_controller.rb). From what I understand of ROR each controller has some basic (inherent) methods such as index, new, create, edit, show, etc. I would like to add a method called "help" and a view to display the help information.

At present a user can create many projects. The projects contain a set of fields that are populated by the user. I would like to add a help page that the user can access (via a link on the project screen) which explains each project field and how to best fill it out. I would like this to be an independent page (not just info displayed on the project's page).

As of now, the URL to the projects is (when editing a project): localhost:3001/projects/id/edit

I would like for the path to the help file to be localhost:3001/projects/id/help

If I want the help file to be located in the path listed above, am I correct in assuming that I need to create a new method, called "help", in the projects controller? And if so, is there something that I need to add to routes.rb to make it function? And would I use a link_to function in the Haml to create a link to it?

I'm sorry if this seems confusing or a lot of question. I appreciate your time. If you have any suggestions on whether on the right path please let me know. Thank you so much!


I think currently you have this in routes

resources :products do  

end

just replace this with

resources :products do  
  get :help, :on => :member, :as => :help  
end

And add method in controller and add view named help.erb.html(if you r using erb) in views/product folder.

you can use help_path and help_url

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜