Create a new action for existing controller

前端 未结 3 952
深忆病人
深忆病人 2021-01-04 09:27

I know this is probably a newbie question, but is it possible to create a new action (method in controller & associated view) from the command line on an existing contro

相关标签:
3条回答
  • 2021-01-04 09:42

    Rails provide posibility of creating custom generators (but this is more advanced subject), which can be tailored for your needs.

    More info:

    http://guides.rubyonrails.org/generators.html

    0 讨论(0)
  • 2021-01-04 09:50

    we can create manually the action in the controller and view but you should also add test statements that because should be good automated process, something like rails generate controller NAME [action action] option m m = merge

    0 讨论(0)
  • 2021-01-04 10:03

    I'm pretty sure you won't be able to do this in a 100% automated way. The reason is that Rails doesn't know what you've done with your routes or controller, and it would require some logic to know how to update these existing files. Your best bet is to just add the new action manually. Add the new method to your controller, update your routes file, and add the view. It will probably take 1 minute at most. Also, if you're not using version controller (which your question eluded to), then you don't have to worry about it automatically overwriting something.

    0 讨论(0)
提交回复
热议问题