Reputation: 171
Is there a way to create my own action?
For example when i use scaffold, in the controller it creates "index", "show", "edit" , "new", "create", "update" and "destroy" actions.
I want to add another action.
I have read that i need to add some code on routes file...
Can anyone help me?
Upvotes: 0
Views: 547
Reputation: 198
You can generate your own actions in a controller simply by defining a method:
def action
# do something here
end
You'll need to make sure you have a route setup in config/routes.rb, too.
For more information, I'd suggest reading the guide at http://guides.rubyonrails.org/getting_started.html, specifically http://guides.rubyonrails.org/getting_started.html#generating-a-controller. You'll find that although scaffolds can be useful initially, you have to write your own controller files / action methods as soon as your application gets more complicated.
Upvotes: 4
Reputation: 5962
Well you can just define the action routing in your routes and way you go
Hope this help
Upvotes: 0