Gem seems to affect other rails project of the same name - ruby-on-rails

I created a rails project MyProject and tried to set up Devise in it (using this tutorial). After I did some Devise stuff I could not scaffold User anymore, I ran into an error as shown below. So I wanted to start over, renamed the project to MyProject-Devise and created a new project MyProject to create User first and then do my Devise stuff. Now in my new project of the same name, when I run
rails generate scaffold user name:string email:string
I run into the same error. If I create a new app with another name, I can scaffold the user with the same command. So I guess it must be the same name thing.
Any ideas why this happens? How to get rid of the error or how to properly start the project over again?
This is the error:
/Users/luke/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.7/lib/active_support/inflector/methods.rb:238:in `const_get': uninitialized constant User (NameError)
Full error here: http://pastebin.com/KFh4U6aS

It looks like you might not be using Bundler. The tutorial you linked to had you create a Gemfile but didn't tell you to run bundle or bundle exec. Without Bundler you may be using a Devise installed directly into your Ruby's gems.
I suspect if you run the rails generate command with bundle exec you may have different results.
bundle exec rails generate scaffold user name:string email:string

Related

Generate devise install returning errors

I'm new to ROR, I have recently included DEVISE into my Rails project but accidentally I ran a wrong command as follows:
rails g devise install
After that rails starting showing errors and not working, even the server is not running now.
Here's a screenshot showing the number of errors I'm getting and their details:
Now even the normal command for installing devise, i.e. devise:install is not working.
Does this command work for you? rails destroy devise:install
This should delete your Devise configuration.

How do I set up user authentication using devise and Rails 4?

I'm trying to get user authentication with devise working, and failing.
I tried following the steps in the RailsGirls article, but after creating the simple new project, adding the gem 'devise' and running bundle install, but when I run rails generate devise:install I get a screenful of errors starting
Error:Get available generators script executes with errors:
Error:C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `devise' for User (call 'User.connection' to establish a connection):Class (NoMethodError)
Has anybody any idea what I might be doing wrong? (I tried using the instructions in the devise wiki, but I couldn't get it working that way either).
I just ran to this same problem today, it's because you tried to generate the model before you tried to install devise it self
Stash ( or remove ) the changes for the user model and any migration file, then run this
rails generate devise:install
after that unstash and apply the migration, it should work just fine.

about rails plugins/engines

I am looking at rails plugins to help me modularize my application. I have some basic questions that I am confused about.
Can a rails plugin have its own DB? My application is very little traffic, for internal use, so I am fine with the idea of separate sqlite DB's for each plugin. When I do a "rails plugin new" even if I use --full, there is no database.yml generated. If I create one and do a rake db:create, no sqlite db is created.
Is there a good tutorial available for creating a rails plugin with rails 3.2? Most I find are older and use the enginex gem which I think is now built into rails.
Can you run your plugin as a standalone app for testing, i.e. using WEBrick? When I run "rails server" in my plugin directory, it just says "Error: Command not recognized".
I guess that's it, I am just confused on how to begin.
Creating Migrations
The Rails Guide "Getting Started with Engines" instructs you to use 'rails g model post' from the root directory for your engine.
Getting Started with Engines
If you do this, it will create the db/migrate folder for you with the migration inside of it.
$ rails g model post
invoke active_record
create db/migrate/20120517184738_create_my_engine_posts.rb
create app/models/my_engine/post.rb
invoke test_unit
create test/unit/my_engine/post_test.rb
create test/fixtures/my_engine/posts.yml
You can also generate migrations directly just the same, just as you do with a Rails app.
$ rails g migration AddMyEngineTable
invoke active_record
create db/migrate/20120517185241_add_my_engine_table.rb
Running Rails Server
The Rails Guide also states to run 'rails s' from test/dummy, not from the root of your engine directory.
I see that from an ASCIICast on the subject which covered Rails 3.1 RC5 that you used to be able to run 'rails s' from the root directory of your engine/gem. This is no longer the case.
From the Rails issue posted on Github three months ago it appears that they needed to keep the scope of the engine separate from the scope of the dummy app.
Issue #4894: Mountable Engines Rails File
In short run from the engine root:
test/dummy/script/rails s

Cucumber: web_steps.rb

I'm wasting my time here and I can't seem to figure this out..
I have used Cucumber in Rails applications before, and if I'm not mistaken, it generates the features/step_definitions/web_steps.rb file when you run rails g cucumber:install. Right?
I looked this up in a book I was using a while ago to learn Rails and it says so there aswell:
It nevertheless passes because of the features/step_definitions/web_steps.rb
file, which was generated when you ran the rails generate cucumber:install command.
However, when I run it in this application I'm trying to start working on, it does not generate it..
$ rails g cucumber:install
create config/cucumber.yml
create script/cucumber
chmod script/cucumber
create features/step_definitions
create features/support
create features/support/env.rb
exist lib/tasks
create lib/tasks/cucumber.rake
force config/database.yml
No web_steps.rb to be found. Am I losing my mind here?
Thanks.
Which version of cucumber are you using? if it is a recent version, see
https://github.com/cucumber/cucumber-rails/blob/f027440965b96b780e84e50dd47203a2838e8d7d/History.md

Rails generate scaffold user:string password: string just creates a new rails folder

I'm new to rails and trying to follow along with railstutorial.org.
When I use Rails generate scaffold user:string password:string, it creates a new folder entitled generate and does the same command as "Rails Demo_App". I'm assuming I don't have something installed correctly.
I'm using Windows 7, Cygwin/Vim/Sqlite3 - I have needed to reinstall Cygwin about 3 times to make sure openssh, git, vim, and other plugins/libraries were installed. I'm assuming I will need to do something similar again.
Also, a Gemfile isn't created with the rails command. Could this be related?
Aren't you supposed to call script/generate scaffold user:string password:string ? AFAIK, calling generate not from app folder may cause incorrect behaviour.
Use script/generate scaffold ... inside of your application directory. The rails command is used to create a new project.

Resources