Reputation: 5193
I would like to generate a scaffolded controller, view and helper named with not pluraled one, but singular one. Howevery, I got pluraled named files like below. I know they are based on the rails convention, but I just would like to create a dictionary page.
$ rails generate scaffold_controller dictionary
create app/controllers/dictionaries_controller.rb
invoke erb
create app/views/dictionaries
create app/views/dictionaries/index.html.erb
create app/views/dictionaries/edit.html.erb
create app/views/dictionaries/show.html.erb
create app/views/dictionaries/new.html.erb
create app/views/dictionaries/_form.html.erb
invoke helper
create app/helpers/dictionaries_helper.rb
So, my question is "Are there any better ways or the shortest way to generate a singular named controller/view/helper files by command?"
What I want is just below. I'm wondering if I should make the files manually?
app/controllers/dictionary_controller.rb
app/views/dictionary/index.html.erb
app/helpers/dictionary_helper.rb
Upvotes: 2
Views: 1946
Reputation: 7405
There is a railsway of doing this, you can use inflections
to document such exceptions:
config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable "dictionary"
end
Upvotes: 4
Reputation: 42899
Well without messing with any thing in rails you can set up the routes using resource
instead of resources
more about that here
You'll still use a plural controller name ( if you need processing ), but the URL will be singular, and you won't have all the actions like the plural resources
( more about that in the link ), if you just want one page then limit by using only: :show
resource :dictionary, only: :show
Then you don't even need the contorller, just create the file dictionaries/show.html.haml
(or erb) and it would work
http://example.com/dictionary
Upvotes: 2