Chinu Chinu - 2 years ago 75
Ruby Question

How to get automatically page URL in ruby like CakePHP?

I am beginner in Ruby on Rails. I have an

there have lots of
approximately 100 more. So it's hard to set in the routers. I want to automatically set action.


def abc
render text: 'Hello World!"
def xyz
render text: 'Bla Bla Bla'

I want my URL should be open this type


No need to set any multi line URL path in routers.

Here below I was write in router. Bu that code not working:

match ':controller(/:action(/:id(.:format)))'

Please help me

Answer Source

The error I was getting using your code was :

You should not use the `match` method in your router without specifying an HTTP method. (ArgumentError)
If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.

On Rails and ruby 2.3.0 the following works :

match ':controller(/:action(/:id(.:format)))', via: [:get, :post]

Please note the , via: [:get, :post].

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download