I've obtained a project that have controllers (minimal code only) and models, but the views are missing. Is there a way to generate the views only using scaffold or another tool?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
- Rails how to handle error and exceptions in model
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
"Another tool"...
How about being able to do "
script/generate view_for model_name
"? :)There is a gem for that - View Mapper. It has Ruby on Rails 2 and 3 versions.
To generate views after controller and models are already created, you may use the command line. You switch to the folder in which you want to create the new view. For example:
To go back of one directory use:
The
--skip
means to skip files that already exist. (The opposite is--force
.)If you don't want helpers,
--helpers=false
.Sample output after deleting my
User
views:This is what the scaffold generator calls internally:
erb
is the templating engine used, so you can also usehaml:scaffold
.You must explicitly specify the fields you would like the scaffolding to use--rails does not automatically deduce them from the created model. For example:
See
rails g --help
for options like skipping, forcing overwriting, and dry runs orgenerate scaffold --help
for information specific to generating scaffolding.I just encounter the same your problem. I did it. More detail is below:
- First I rename views/your_model folder to views/your_model_bak. In order to revert if fail later
- Then, execute command
-- Finally, you should update your permit in your_model controller.
Hope it can help you.
One small tip is to add "
--no-test-framework
" if using Rspec and don't want test files generated for each view in spec/views