Pretend with rails generator
how to pretend rails generate to see if generated files will conflict
The rails generate command will be used many times during the lifetime of a project. Sometimes the generate may create or modify multiple files that you may not want to. If you need to find out what files will be created/modified, you can run a pretend generation. Here let’s try generating model that will conflict with already created model:
$ rails g model ticket owner:string status:integer assigned:string subject:string next_step:enum type:enum -p
invoke active_record
conflict db/migrate/20160510153738_create_tickets.rbNow, let’s pretend to generate model that has never been created in the app before:
$ rails g model comment body:text post_id:integer -p
invoke active_record
create db/migrate/20160510153812_create_comments.rb
create app/models/comment.rbIn the first case we were told that migration file has already been created and will conflict while second generator ran smoothly. Since we were just pretending, no new files were actually created but we were able to analyse when generate command would create conflicting files in project.
I am yet to really make use of this feature but hopefully it will come handy someday in future.
References:
- <a href=https://www.airpair.com/ruby-on-rails/posts/ruby-rails-tips-hacks rel=“nofollow” target=“_blank”>https://www.airpair.com/ruby-on-rails/posts/ruby-rails-tips-hacks
Keep reading
Fix mise GitHub Rate Limit with a Token
mise makes unauthenticated GitHub API calls by default. When you hit the rate limit installing tools, a personal access token (no scopes required) fixes it permanently.
How to solve Deployment Failure-`assets:precompile`
I was trying to deploy rails 6 app on ec2 server using capistrano when precompile failure lead to whole deploymentt failure. I had to uninstall cmdtest and install yarn
How to Sort an Array of Objects in JavaScript
How to Sort an Array of Objects in JavaScript
What did you take away?
Thoughts, pushback, or a story of your own? Drop a reply below — I read every one.
Comments are powered by Disqus. By posting you agree to their terms.