Don't create view folder on rails generate controller
It's not a well documented feature, but try to add --skip-template-engine
(alias --no-template-engine
) option to the command.
rails generate controller foo bar --skip-template-engine
demo on a dummy app:
rails g controller my_controller index show --no-template-engine
create app/controllers/my_controller_controller.rb
route get "my_controller/show"
route get "my_controller/index"
invoke test_unit
create test/functional/my_controller_controller_test.rb
invoke helper
create app/helpers/my_controller_helper.rb
invoke test_unit
create test/unit/helpers/my_controller_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/my_controller.js.coffee
invoke scss
create app/assets/stylesheets/my_controller.css.scss
Why doesn't g controller also create view file?
Use rails generate scaffold instead which will generate the model, view and controller files for you in a single operation.
If you want to create the models, views, and controllers for a new
resource in a single operation, scaffolding is the tool for the job.
e.g.:
rails g scaffold Post name:string title:string content:text
But, if you really want to use rails g controller
and also create the view files for you, then you have to specify the action
names for your controller:
rails g controller Controllername index show edit update
This way, it will create the view files for these four actions: app/views/.../index.html.erb
, app/views/.../edit.html.erb
. . . etc.
But, looking at your case, you should use scaffolding as it will do a lot of work for you.
Ruby On Rails Not Creating The View For A Controller
Unless you created an API only project with the --api
flag, the rails generate controller Welcome index
command should have created an index.html.erb
file in the views folder.
You can either delete the welcome_controller.rb
file and the generated line from the route.rb
file and run the command again or you can manually create the view with the touch
command (assuming your OS supports the touch
command):
touch app/views/welcome/index.html.erb
or through you favourite text editor or IDE. On a side note, controller names should be plural (WelcomePagesController
for example).
Ruby on Rails generating controller with existing folder
To answer your question :
New files will be added to the existing folder but existing files will not be merged, you'll have to resolve the conflict by choosing between old and new files.
It seems to me you're trying to use generators for every action you need in your app :
Scaffolding is great to have a sample structure, but as soon as you start building your controller for real you need to move away from it : extend the controllers, models and views by hand. It's the only way you'll start to really understand how things are working.
Syntax to skip creating tests, assets & helpers for `rails generate controller`?
Try using --no-
followed by optionname
:
rails generate controller home index --no-helper --no-assets --no-controller-specs --no-view-specs
If you want to change the default behavior every time you run the generator command, you can configure the defaults you would like in the application.rb file - see How can I make sure Rails doesn't generate spec tests for views and helpers?.
Rails create admin controller and view in other directory and with own style
Have a look at this link, where they use the same admin subdirectory grouping (link broken) example. The example is for an older version of Rails, but should be relatively valid for Rails 3.2.
Edit: See this namespaces question.
rails generate controller admin/Users
For bootstrap, just don't use the bootstrap specific id/class attributes in your admin stylesheet.
Related Topics
How to Use Capybara in Pure Ruby (Without Rails)
Is Ruby a Scripting Language or an Interpreted Language
Anybody Tried the Crystal Programming Language (Machine-Code Compiled Ruby)
Rails Project Using Spork - Always Have to Use Spork
What Are the Reserved Words Begin or End Used for in Ruby
How to Monitor Uptime of 20 Websites (Ping or Http) in Node.Js/Ror
Rails: Render Doesn't Work, Still Get 'Template Is Missing'
Ruby: Put Request with JSON Body
How to Load a Spec_Helper.Rb Automatically in Rspec 2
Rails 5.2 Active Storage Add Custom Attributes
Passing Param Values to Redirect_To as Querystring in Rails
Rails: Your User Account Isn't Allowed to Install to the System Rubygems
Cool Tricks and Expressive Snippets with Ruby Collections/Enumerables
Cucumber, Capybara and Selenium - Submitting a Form Without a Button