rails generate scaffold but prevent the model file from being generated - ruby-on-rails

I have looked over the documentation at rails generate scaffold -h but am still stumped. I want to create all the files from the scaffold generator except the model file.
Example:
rails generate scaffold User --no-model
This as it is does not work but what I would like to happen is that the user.rb file is prevented from being created within the models directory.

Figured it out! You just need to include --skip to tell rails that for any conflicting files to just ignore creating those files.
Example: say I already have the file user.rb inside my models directory:
rails generate scaffold User --skip
With the --skip option rails knows to skip creating the user.rb file, as well as all other already existing files that the scaffold command would generate for this resource.

Related

Devise views not generating

Devise works. I can login and log out, but there are no views in the my project. There is no app/views/devise folder. When I used rails g devise:views nothing appeared. How is Devise even working if there is no html, and how can I get these views to display in my project so I can edit them?
If files are not added, the files added into your gem folder and Devise will use them, but when you run the command, the created folder will just overwrite them.
If rails g devise:views still not working for you, one easy way to do this instead of trying to find what was the issue with the gem or Terminal is to just move them yourself.
Here you have the files Devise views, just copy paste them into your folder and you will be good.
Go to the application root directory and run following command to get views of devise:
rails g devise:views
I read on the documentation that you have to put this line in config/initializers/devise.rb
config.scoped_views = true
you will have access to the file for sessions,
and you can do too :
rails generate devise:views users
to have access to user files
You should take a look : https://github.com/plataformatec/devise
Hope that help

new scaffold generator with some default files

I am making a new rails scaffold generator to replace the default one, most of the files remain the same, only some are different. So how do I invoke some of the default scaffold files within my generator?
Also, is there a way I can checkout the source code of the original scaffold generator?
The source code is in the railties section of the project on github. To gain access to the scaffold templates, I would just invoke the actual scaffold generator and then gsub the files if you need to make changes.

My custom devise views aren't displaying

I created the /views/user/ folder using rails g devise:views but devise is still using the default views somehow.
Am I missing a configuration somewhere?
Yes, read documentation and add to your config/initializers/devise.rb
config.scoped_views = true
Also see that rails g devise:views create app/views/devise containing all needed views. If you don't have many Devise Models in your app DO NOT use above solution but simply edit files in app/views/devise. Then it will work faster, because it don't need to look every time for specified views.

Devise - Where is the new.html.erb file located?

I just added users to my application using devise, and everything is working fine. But I can't see any folder of the type /views/users where I can change the new.html.erb and edit.html.erb to add new fields?
Does anyone know where these files would be located?
run
rails generate devise:views
that will place the view files in the views directory
From the docs:
Since Devise is an
engine, all its views are packaged
inside the gem. These views will help
you get started, but after sometime
you may want to change them. If this
is the case, you just need to invoke
the following generator, and it will
copy all views to your application: rails generate devise:views
You should run rails generate devise:views task to generate views

Ruby on Rails add models for existing plugin?

I am new to Ruby On Rails, and currently trying to modify an existing (uncomplete) plugin from github. Things went smoothly until I am trying to add new models to this plugin.
I know script/generate model, and script/generate plugin. But how to add models into a plugin without regenerate the whole plugin? I don't want rewrite the plugin to add functions to it, and script/generate model vendor/plugin/myPlugin wilt generate other stuff into the whole project rather than the plugin directory.
Probably I could write the model class file myself, but how about migration, create my own rake file?
Note: The plugin has more than one classes and a couples of migrate schema named as datetime_create_model_name.rb. But I couldn't find any generator in the plugin Dir?
Write a generator for the plugin, to create the migration scripts for the new model. Refer to some of the existing plugins, to learn how to write a generator.
Here is one example:
1) Generator file
2) Migration template file

Resources