I am starting a new project, and have done this meany times now. However, this is the first time I have run into this issue!
I created the app as normal rails new myapp -d postgresql
I've created the DB using rails db:create
and ran the site rails s
. It all works, and I see the Rails welcome/holding page.
Now I start to create my models, rails g model user
for example. And I get this!
Expected string default value for `--jbuilder`; got true (boolean)
invoke active_record
The name 'User' is either already used in your application or reserved by Ruby on
Rails. Please choose an alternative and run this generator again.
Ok that's fair enough, I understand the error message. So I thought I would try to create a different model. When I run rails g model testing
, and I get...
Running via Spring preloader in process 31815
Expected string default value for '--jbuilder'; got true (boolean)
invoke active_record
create db/migrate/20161217171019_create_testings.rb
create app/models/testing.rb
invoke test_unit
create test/models/testing_test.rb
create test/fixtures/testings.yml
Has anyone else had this issue and if so any ideas why? I have tried running bundle install
and bundle update
with no luck. I have also tried setting the thor version as mentioned in this post
I am using Rails 5.0.0.1 and Ruby 2.3.1. I noticed this has only just started happening since I did an update to macOS to 10.12.1 I am not sure if they are related.
So I started to test this out. And I created a couple of different projects 'rails new testapppg' and 'rails new testapp-pg'.
On both of apps I changed the thor gem gem 'thor', '0.19.1'
. I then went on to run bundle update, and create the DB. Now both of these projects created the test models when running rails g model sample
Cool! So that is the fix. So I went back and recreated my pxl-insight app, updated the thor gem, created the DB. Now when I went to create the model I get the errors again!?
So my next question is does Rails cache project names? which is why the new projects worked fine, but the one with the previously used name causes the error?
I got this error yesterday. I also fixed by downgrading thor gem. gem 'thor', '0.19.1'
When I wanted to generate again my app with a same name, or model in the command line it was hanging for a long period and nothing happend. I tried closing and reopening the terminal ( which others claimed that worked for them, so it could be another solution ) but it didn't work for me.
I fixed it by deleting /bin
directory in my project and run: bundle install --binstubs
which will regenerate bin directory again. Probably some paths from the previous project, were in the bin directory.
I hope it helps
Try setting Thor explicitly to the version you want.
In my Gemfile, I set the version to 0.19.1 and I also reject versions that I know are bad, in case a teammate edits the file, or to protect the app if a teammate runs bundle update.
Example:
rails new myapp -d postgresql --skip-bundle
cd myapp
echo "gem 'thor', '0.19.1', '!=0.19.2', '!=0.19.3', '!=0.19.4'" >> Gemfile
bundle install --binstubs=binstubs --path vendor/bundle
bin/rails generate controller Welcome index
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With