Reputation: 26732
When I run this:
rails generate controller hello index
it no doubt generates hello controller, but accidentally when I run another command like this:
rails generate controller world
it creates the world controller successfully, but missed the Route "world/index"
like as "hello/index". For this mistake I need to use destroy controller
and then generate it once more, is thr some kind of mid way command that I can generate if forgotten something rather than destroying and creating every time.
This command
rails generate controller contact-us index
creates a route as contact_us/index
or contact_us
after changing routes.rb under config folder. How could I create a more SEO friendly URL in RoR? Like localhost:3000/contact-us
?
I am working on some very basic rules to follow RoR..like 3 static pages (Home, About us, Contact Us) Just simple html content to understand more, will certainly add more features to it as well.
localhost:3000/home
localhost:3000/About_us
localhost:3000/contact_us
I created this via creating home, About_us, contact_us controller command and then changed html in views. Since I am on an initial phase, I read somewhere for static pages we can create this in our public like what we have error pages there in the folder or the approach im using is correct?
Upvotes: 0
Views: 127
Reputation: 2014
when you use rails generator it will create controller and view folder for it
rails generate controller test
will create test_controller.rb and view/test folder rails generate controller test index will create test_controller.rb and view/test/index.html.erb file as well as define a route for you
However what its sounds like you are trying to do is have single controller with static pages what i would suggest you do is generate home_controller with home, aboutus, and contact actions and than map the routes to them like so
rails generate controller home
controllers/home.rb
HomeController < ApplicationController
def index
end
def about_us
end
def contact
end
end
routes.rb
match '/home', :to => 'home#index'
match '/About_us', :to => 'home#about_us'
match '/Contact_us' , :to=> 'home#contact_us'
and than define your views in
views/home/index.html.erb
views/home/about_us.html.erb
views/home/contact_us.html.erb
Upvotes: 1