mrg mrg - 1 year ago 98
Ruby Question

Setting default page for Controller in Rails

In rails how to set the default page for controller. In my application I have a controller named "greet" which have two actions "welcome"
and "wishes". So while calling the welcome page like "localhost:3000/greet/welcome" is properly worked.

But My requirement is if I didn't
give the action name for that controller like "localhost:3000/greet", then it takes the default page associated for that controller only. How to do this
in rails 4.2. I tried to make an index action within greet controller. But it didn't work. Can anyone help me to solve this problem ?

Answer Source

in your routes.rb add line:

get '/greet' => 'greet#welcome'

you must also in folder view create folder greet and in this folder you have to create file welcome.html.erb

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