Starting a Rails 5 project with Devise and Mongoid - ruby-on-rails

I'm trying to create a Rails 5 API with admin views using mongodb and devise for auth. I know the process can go a lot smoother if everything is set up correctly from the beginning. What sort of terminal commands would I need to run to specify to rails what to leave out and what to add in?
i.e. rails new myapp --no-activerecord --db=mongodb --with-devise
There's one tutorial online but its Rails 3 from 2012.

As per the description mentioned in the post, please follow the below mentioned points:
Create a new project using below mentioned command
rails new name_of_the_project --skip-active-record
name_of_the_project = specify the name which you want to keep
--skip-active-record = this will skip loading active-record as an ORM.
Then you need to add mongoid to the gemfile, so that rails can know you want to use it as an ORM
gem 'mongoid', '~> 6.2.0'
After adding , then run following command
bundle install
rails g mongoid:config
The last command configures, mongoid such as generating mongoid.yml.
Hope this answers your question.

Related

Vanity gem: strange rails generate vanity error

I'm trying to introduce the Vanity gem into a project and everything is happy right up until I try to run the generator. This is the call:
rails generate vanity
And this is the output:
Could not find generator 'vanity'. Maybe you meant 'vanity', 'task' or
'mailer'
Run rails generate --help for more options.
Notice that it can't find 'vanity' and then suggests vanity. Wut? I then took a moment to verify that the generator actually exists:
rails generate --help | grep "anity"
and got:
Vanity:
vanity
vanity:views
I am using Spring, so I stopped that with spring stop.
I should also note that I tried a bunch of things like:
rails generate Vanity:vanity
rails generate vanity:vanity
rails generate Vanity
rails generate oh:please:do:vanity
Additionally, I am actually using bundler so I tried ALL these things with and without bundle exec at the beginning of the commands.
I wonder if perhaps this error is actually masking an issue in my local setup, but I've looked really closely and am convinced that the installation and setup of vanity is correct.
Version information:
ruby 2.5.5p157
Rails 5.2.3
Vanity 3.0.0
EDIT: additional information: I went down the path of stopping the Spring server, bundle update and then trying the generator--nothing changed. I've even tried going into the actual generator and debugging there. While it loads the file, it never executes any of the methods.
Solved this on my own. It turns out that the vanity gem wasn't automatically pulling the generators into the load path. That means that when the generator was called, it was erroring out because it couldn't find the actual generator class in the first place.
The generator error was masking that error and making it look like the generator itself couldn't be found.
The fix for this was to explicitly require the generators in a config/initializers/vanity.rb file.
The vanity gem claims that in Rails apps the classes are "automagically" available.

Having some problems using Rails 3, keeps going to Rails 4

I'm relatively new to Ruby, and Rails, I need to use Rails version 3.2.19, for some tutorials I'm following along, I get all kinds of errors trying to follow along with Rails 4...anyways, when I do: gem install rails --version=3.2.19, it shows that it installed it. When I do rails -v, it shows Rails 4.1.5....I thought maybe if I create a new Rails app, specifying version 3.2.19, that would work. Surprise, it showed up as Rails 4.1.5 in my Gemfile...what gives? I tried manually changing it in the Gemfile and running bundle install, but then everything breaks when I fire up the Rails server...I searched those errors on here, and no surprise, all the answers were about how those are errors when trying to use Rails 3, in an app that was generated with Rails 4.
I'm really stumped about this folks and would appreciate any help! Thanks in advance!
1)please install rvm if YES,check the rvm ls
and set ruby 1.9.3 as default.and then make new project
2)can you see the which version of ruby using if 2+ then it will be rails 4
if you want to use rails 3 then use 1.9.3 ...
Are you doing rails _3.2.19_ new myapp
when you're generating your app?
Also when you change rails version on your Gemfile, you have to run bundle update rails to update the version.

/config/initializers/secret_token.rb not being generated. Why not?

Currently going through a rails tutorial and I need to make some modifications to /config/initializers/secret_token.rb, however, I can't find this file anywhere within the initializers directory. I am running the latest version of rails. This is the line I used in the terminal to create a rails project:
rails new sample_app
Anyone know why it isn't showing up?
Thanks for pointing this out. The issue is probably due to using Rails 4.1 instead of Rails 4.0 as specified in the Rails Tutorial. It's because of issues like this that Section 1.2.2 states (bold in original)
Unless otherwise noted, you should use the exact versions of all software used in the tutorial, including Rails itself, if you want the same results.
To get things to work, first uninstall the current version of Rails:
$ gem uninstall rails railties
Then follow the instructions exactly as written in the tutorial to install Rails 4.0:
$ gem install rails --version 4.0.4
Generating a test app (skipping Bundler for convenience) and piping the output through grep then verifies that secret_token.rb gets generated:
$ rails -v
Rails 4.0.4
$ rails new test_app --skip-bundle | grep secret_token
create config/initializers/secret_token.rb
At this point, you should be able to follow the rest of the tutorial as written.
By the way, I'm about to start work on a 3rd edition of the tutorial, and will plan to take care of this issue as part of a more general update.
The tutorial you're looking at was likely written for an older version of Rails than you're using.
secret_token.rb existed in Rails 3 and Rails 4.0 apps; it does not exist in Rails 4.1 apps.
It has been replaced in Rails 4.1 by the secrets.yml file:
http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml
I am using 4.1.1. Dont copy nothing to the secrets.yml, just dont forget to update the gitignore file (http://www.railstutorial.org/book/beginning#code-gitignore)
With this you can keep going on the tutorial

Ruby on Rails generators with new gemified plugin?

I'm attempting to create a new Rails 3 plugin gem which wraps around devise/devise_ldap_authenticatable for reusable drop in internal LDAP support.
I create the new plugin gem with:
rails plugin new <gem_name>
I then add the devise/devise_ldap_authenticatable gems to the .gemspec file and run bundle
In the devise instructions it says to generate the required files using its generators:
rails generate devise:install
rails generate devise MODEL
However, in the directory where the plugin is generated I don't seem to be able to run rails generate. Most gem plugin tutorials instruct you to just create the files manually. Am I better off starting a new rails project, following the instructions in the temp project, then copying the files over to the plugin manually? Is there something that I'm missing? Can I run the generator script from the dummy instance? What is the standard practice in this use case?
In the end, I opted to forgo wrapping devise_ldap_authenticatable due to its relative simplicity.
The answer that I would go with in the future is to just to move files from a throwaway project.

Missing script/generate in Rails 3

I just installed Rails 3 and created my first app. The install of Rails3 + ruby 1.9 went very smoothly but I am missing the generate script in script/generate.
I have created a new app from scratch with no options to verify.
Any idea why this is happening and how to fix it?
all script/* commands has been removed from rails 3. You should use rails generate or rails g instead of script/generate, rails server or rails s instead of script/server and so on.
try
rails generate ...
the only script existing now is rails all others will be called as parameter of rails.
Take a look a the Ruby on Rails Guides: Getting Started with Rails

Resources