Don't Create View Folder on Rails Generate Controller

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



Leave a reply



Submit