Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

adding options to erb scaffold generator to include or skip custom views / templates

#5319

When I was working on customizing the erb scaffold generator to match the style and design I wanted to use by creating custom templates in /lib/templates/erb/scaffold I found that I wanted to add additional files.

I can now do something like the following:

$ rails generate scaffold FitType key:string name:string description:text --add-views=_nav --skip-views=new ...

  invoke    erb
  create      app/views/fit_types
  create      app/views/fit_types/index.html.erb
  create      app/views/fit_types/edit.html.erb
  create      app/views/fit_types/show.html.erb
  create      app/views/fit_types/_form.html.erb
  create      app/views/fit_types/_nav.html.erb

Reported by Deleted User · August 6th, 2010 @ 07:09 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Deleted User
  2. Robert Pankowecki
    Robert Pankowecki

    It seems quite nice but is it much better than just removing or adding those files later by yourself like

    rails generate scaffold ... && rm app/views/fit_types/new* && touch app/views/fit_types/_nav.html.erb
    

    ?

    August 7th, 2010 @ 10:44 AM

  3. Deleted User
    Deleted User
    • Tag cleared.

    Much better? IMHO yes..

    Since by having it as an option, I can set the argument in the configuration file, and not have to type anything extra at all for each invocation, allowing me to have the scaffolding the way I want it, each and every time I invoke it.

    This is about saving time, and keystrokes so After invoking the scaffold, I have either no changes necessary, or very minimal changes to make to make the resulting pages meet functional and aesthetic spec.

    August 8th, 2010 @ 08:23 PM

  4. Deleted User
  5. Andrea Campi
    Andrea Campi
    • Tag changed from patch to generators, patch

    +1

    Also, I verified the patch still applies cleanly and works as advertised.

    October 9th, 2010 @ 05:24 PM

  6. Ryan Bigg
    Ryan Bigg
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    October 11th, 2010 @ 12:10 PM

  7. Aditya Sanghi
    Aditya Sanghi

    +1

    Seems nice. I like more options on generators and such like.

    The patch could do with some tests though.

    October 13th, 2010 @ 06:27 PM

  8. Aditya Sanghi
    Aditya Sanghi
    • State changed from new to incomplete
    • Tag set to patch

    Marking incomplete till we have patch with tests.

    October 13th, 2010 @ 06:28 PM

  9. Deleted User
    Deleted User

    Please excuse me being new to this, but how would I write a test for this?

    October 19th, 2010 @ 04:56 PM

  10. Andrea Campi
    Andrea Campi
    • Tag changed from patch to generators, patch

    Try looking at @railties/test/generators/scaffold_generator_test.rb@, as well as the documentation for run_generators in @railties/lib/rails/generators/test_case.rb@; that should give you a starting point.

    October 19th, 2010 @ 10:14 PM

  11. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    November 7th, 2010 @ 04:56 PM

  12. Jeff Kreeftmeijer
  13. Santiago Pastorino
    Santiago Pastorino
    • State changed from incomplete to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 9th, 2011 @ 12:31 AM

  14. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 9th, 2011 @ 12:31 AM