railsapps / rails3-mongoid-devise Goto Github PK
View Code? Open in Web Editor NEWAn example Rails 3.2 app with Mongoid for data, Devise for authentication.
Home Page: http://railsapps.github.io/
An example Rails 3.2 app with Mongoid for data, Devise for authentication.
Home Page: http://railsapps.github.io/
In login_items.html.haml
= link_to('Logout', destroy_user_session_path, :method=>'delete')
You have to include the method in order for it to route properly. Appears to be a devise bug.
Hi, I just started an app with the provided generator and it fails with this error:
generate rspec:install
/home/julien/.rvm/gems/ruby-1.9.3-p125/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
All you have to do is add these to the Gemfile:
gem 'execjs'
gem 'therubyracer'
Regards
I was going through the tutorial and was getting thrown an error on Mongoid.master. It seems it's not supported in the latest Mongoid anymore. I'm not sure if Mongoid.purge is considered the best option here, but I here's the updated code I got working:
puts 'EMPTY THE MONGODB DATABASE'
Mongoid.purge!
puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => 'First User', :email => '[email protected]', :password => 'please', :password_confirmation => 'please'
puts 'New user created: ' << user.name
I am using Devise with cancan ,Bootstrap with rolify.
Here i make edit of user account to admin and it is done by makin update method
def update
authorize! :update, @user, :message => 'Not authorized as an administrator.'
@user = User.find(params[:id])
params[:user].delete(:password) if params[:user][:password].blank?
params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
if @user.update_attributes(params[:user])
redirect_to users_path, :notice => "User updated."
else
redirect_to users_path, :alert => "Unable to update user."
end
end
This codes work but it does not works for Changing role of the users
if @user.update_attributes(params[:user], :as => :admin) it works for role But not update
if @user.update_attributes(params[:user])it works for update but not roles. Any idea to implement this both situation?
When adding Cucumber steps to an app derived from this example app (one of its major use cases), I noticed their user authentication code had changed quite a lot. Generally, it seems this will happen.
The part of the cukes using FactoryGirl no longer worked. Now, I am sure someone familiar with FactoryGirl can keep an altered app's cukes working.
However, for something more easy and direct for newbies, isn't it better to drop FactoryGirl from the user model and use pure Capybara in the Cucumber user steps?
Hi,
Don't know if this is pilot error or what, but I thought I'd mention it in case it's helpful. For some reason I was having trouble with the DatabaseCleaner code in spec_helper.rb, complaining about the mongoid connection. Because there was no connection, needless to say all the tests were failing. My solution was to yank out DatabaseCleaner and add code based on http://adventuresincoding.com/2010/07/how-to-configure-cucumber-and-rspec-to-work-with-mongoidra, specifically:
config.before :each do
Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
end
Works like a champ now, all tests passing.
The Configure Email section of README informs us this example Rails app doesn't send out email.
Presently, GMAIL_USERNAME and GMAIL_PASSWORD are generated in config/application.yml. Perhaps they are useful only for sending outgoing email.
Therefore, perhaps they should be removed, so having two usernames and passwords doesn't puzzle beginners.
I run the following command:
rails new myapp -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-mongoid-devise-template.rb -T -O
Then I got following errors:
run bundle exec rake db:migrate from "."
rake aborted!
Problem:
Invalid index specification on Role: name, {:unique=>true}
Summary:
Indexes in Mongoid are defined as a hash of field name and direction/2d pairs, with a hash for any additional options.
Resolution:
Ensure that the index conforms to the correct syntax and has the correct options.
Valid options are:
background: true|false
drop_dups: true|false
name: 'index_name'
sparse: true|false
unique: true|false
Valid types are: 1, -1, '2d'
Example:
class Band
include Mongoid::Document
index({ name: 1, label: -1 }, { sparse: true })
index({ location: '2d' }, { background: true })
end
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
generate devise_invitable user
insert app/models/user.rb
invoke mongoid
seed_database creating indexes and seeding the database
run rake db:mongoid:create_indexes from "."
rake aborted!
Problem:
Invalid index specification on Role: name, {:unique=>true}
Summary:
Indexes in Mongoid are defined as a hash of field name and direction/2d pairs, with a hash for any additional options.
Resolution:
Ensure that the index conforms to the correct syntax and has the correct options.
Valid options are:
background: true|false
drop_dups: true|false
name: 'index_name'
sparse: true|false
unique: true|false
Valid types are: 1, -1, '2d'
Example:
class Band
include Mongoid::Document
index({ name: 1, label: -1 }, { sparse: true })
index({ location: '2d' }, { background: true })
end
Tasks: TOP => db:mongoid:create_indexes => environment
(See full trace by running task with --trace)
run bundle exec rake db:seed from "."
rake aborted!
Problem:
Invalid index specification on Role: name, {:unique=>true}
Summary:
Indexes in Mongoid are defined as a hash of field name and direction/2d pairs, with a hash for any additional options.
Resolution:
Ensure that the index conforms to the correct syntax and has the correct options.
Valid options are:
background: true|false
drop_dups: true|false
name: 'index_name'
sparse: true|false
unique: true|false
Valid types are: 1, -1, '2d'
Example:
class Band
include Mongoid::Document
index({ name: 1, label: -1 }, { sparse: true })
index({ location: '2d' }, { background: true })
end
Tasks: TOP => db:seed => environment
(See full trace by running task with --trace)
The Set the Database section of the README says:
'Use rake db:reset if you want to empty and reseed the database'
However, rake db:reset
doesn't exist, since we're using the mongoid gem (and Rake gives an error).
Per rake --tasks
, this should be rake db:reseed
(or so it seems).
After running:
rails new projectname -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-mongoid-devise-template.rb -T -O
The code reads: gem "guard", ">= 0.6.2", :group => :developmentcase HOST_OS
Should have a newline between "development" and "case" I think?
Rails 3.1.3
when i m editing index.html.erb in notepad and try to save ,its the message"this file is opened in another program"
In the navigation header, the user sees 'Login' and 'Logout' (in _navigation.html.haml); user_steps.rb contains 'Login' and 'Logout'.
On the other hand, Devise seems to prefer something else: once a user clicks Login, bold letters say 'Sign in' (in app/views/devise/shared/_links.html.haml).
Following Devise, sign_out.feature contains 'Feature: Sign out', sign_in.feature contains 'Feature: Sign in', and support/paths.rb contains 'sign in'. Some step definitions include 'logged in' and 'not logged in'.
I know it all works, yet newby users will be customizing the cukes for their apps.
Perhaps usefully, 'Log' and 'Sign' (in the features) have slightly different meanings. Yet, to make things easiest, and for elegant simplicity, isn't it better to use 'Sign in' and 'Sign out' only, always and everywhere?
Probably otherwise, people will wonder, and spend time figuring out, what the difference is. If useful, the difference could be documented for newby users.
Hi,
Are there any plans to upgrade this to use Mongoid 3.0?
This seems to be a known issue. See here: thoughtbot/factory_bot#156
After using the generator, put this in the gem file:
gem "factory_girl", :git => 'git://github.com/thoughtbot/factory_girl.git', :tag=>'v2.0.0.rc1'
I noticed one failing test in user_spec.rb when running 'rspec spec' for the first time:
Failures:
Finished in 2.11 seconds
17 examples, 1 failure
I got the test to pass after adding email validation to the user model using an example from ASCIICasts found here: http://asciicasts.com/episodes/211-validations-in-rails-3:
validates :email,
:presence => true,
:uniqueness => true,
:format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i }
After which, the test passes:
.................
Finished in 1.87 seconds
17 examples, 0 failures
Not sure if anyone else ran into this issue but wanted to share.
Thanks,
Walter
having worked several times before, but the most current version of the template is puking on me when attemtping to run seed:db from the generator template....
Im running in a new gemset on my localhost RVM 1.9.2 , resulting in the following error.... I cant seem to track down the reason.
Anyone else having this issue?
$ bundle exec rake db:seed
SETTING UP DEFAULT USER LOGIN
rake aborted!
undefined method `[]' for nil:NilClass
Tasks: TOP => db:seed
(See full trace by running task with --trace)
Thank you for those amazing tutorials.
I run into an issue when i try to exec the rake task "assets:precompile" on non modified code.
This is the trace :
$ rake --trace assets:precompile
** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
db_name must be a string or symbol
Tasks: TOP => environment
Thanks,
Mickael.
gsub app/models/user.rb
gsub app/models/user.rb
gsub app/models/user.rb
run rails generate devise:views from "."
/app/models/user.rb:2:in `<class:User>': undefined local variable or method `rolify' for User:Class (NameError)
from /app/models/user.rb:1:in `<top (required)>'
The README recommends users set up their test environment with db:test:prepare
.
However, automatically now during testing, Rails itself does db:test:prepare
, as revealed by bundle exec rake --trace
. So, this step in the README doesn't add anything.
This is similar to an issue in another Rails Example App.
Under the heading "Create a Default User" the instructions read:
"Modify the file app/controllers/home_controller.rb and add:"
def index
@users = User.all
end
Well, in that specified file, there already exists the lines
"def index
end"
I first appended the instructed 3 lines of code to the end of that file, which led to an error. I was able to troubleshoot that error (which seemed to be in the next file referenced by the instructions) and found that the issue was that I was suppose to just add that second line " @users = User.all" in between the 2 lines already given in my file. I'm brand new to this so simply following the instructions I did not know (if) this was meant. Perhaps say to write that one line of code between the other 2 rather than "add the following code."
Other than that, all else has been amazing! Thanks for a very helpful tutorial!
Step to reproduce :
- Create a new empty project with the rails3-mongoid-devise template.
- After starting the server, Iogin into the app with [email protected]/please.
The page show the following error :
BSON::InvalidObjectId in UsersController#show
illegal ObjectId format
app/controllers/users_controller.rb:5:in `show'
Request
Parameters:
{"id"=>"1"}
Here is my Gemfile :
source 'http://rubygems.org'
gem 'rails', '3.0.9'
gem "haml", "3.1.2"
gem "haml-rails", "0.3.4", :group => :development
gem "rspec-rails", "2.6.1", :group => [:development, :test]
gem "database_cleaner", "0.6.7", :group => :test
gem "mongoid-rspec", "1.4.2", :group => :test
gem "factory_girl_rails", ">= 1.1.rc1", :group => :test
gem "cucumber-rails", ">= 1.0.2", :group => :test
gem "capybara", "1.0.0", :group => :test
gem "launchy", "0.4.0", :group => :test
gem "mongoid", "2.0.2"
gem "devise", ">= 1.4.2"
gem "bson_ext", ">= 1.3.1"
Thank you for the amazing tutorial. I have never encountered a better walkthrough. I ran into one small error.
I followed the link to change the application layout to:
http://railsapps.github.com/rails-default-application-layout.html
I then copied the erb code for Rails 3.1, that included this snippet:
<title><%= app_name %></title>When I ran the server I received an error:
undefined local variable or method `app_name'
I only mentioned it because it was the only error, I received.
For whoever must use MongoDB versions earlier than 2.2.0, please update these docs (README and tutorial section 'Installing MongoDB') similar to your comment and pull request for Rails Example App rails3-mongoid-omniauth.
On the Debian GNU/Linux operating system, as of March 2013, the latest stable version is MongoDB 2.0.0. With MongoDB 2.0.0, the Mongoid gem must be version 3.0.x. See the "Mongoid installation instructions":http://mongoid.org/en/mongoid/docs/installation.html#installation. Change your Gemfile to use an earlier Mongoid version:
+
+<pre>
+gem 'mongoid', '~> 3.0.1'
+</pre>
I cannot confirm this being an issue, but maybe a note is required within the deploy to Heroku section that the MongoHQ and MongoLab Heroku add-ons support up to MongoDB 1.8 at the present time?
I'm unable to get about 5 steps to pass in cucumber.
Failing Scenarios:
cucumber features/users/sign_in.feature:24 # Scenario: User signs in successfully with email
cucumber features/users/sign_out.feature:6 # Scenario: User signs out
cucumber features/users/sign_up.feature:6 # Scenario: User signs up with valid data
cucumber features/users/sign_up.feature:15 # Scenario: User signs up with invalid email
cucumber features/users/user_edit.feature:6 # Scenario: I sign in and edit my account
For instance:
Scenario: I sign in and edit my account # features/users/user_edit.feature:6
Given I am a user named "foo" with an email "[email protected]" and password "please" # features/step_definitions/user_steps.rb:5
When I sign in as "[email protected]/please" # features/step_definitions/user_steps.rb:43
illegal ObjectId format (BSON::InvalidObjectId)
./app/controllers/users_controller.rb:6:in show' (eval):2:in
click_button'
./features/step_definitions/web_steps.rb:53:in /^(?:|I )press "([^"]*)"$/' features/users/user_edit.feature:8:in
When I sign in as "[email protected]/please"'
Then I should be signed in
mongoid url no need for this thread
The Test the App section of the README says:
To sign in as the default user, (unless you’ve changed it) ...
and gives a password.
However, this password differs from the default password (for the Admin user) in config/application.yml.
A certain subtlety exists regarding rake cucumber
and Cucumber's standard Work In Progress cukes (those tagged with @wip
).
rake cucumber
has the same effect as rake cucumber:ok
. It does not have the same effect as rake cucumber:all
.
In light of this, the following statement in the Testing section of the README:
'Run rake cucumber (or more simply, cucumber) to run all Cucumber scenarios'
perhaps (to avoid misleading newbies to Cucumber) should be changed to:
'... all Cucumber scenarios (that are not tagged with @wip, for work in progress. And if you don't know what that means, then you don't need to worry about it).'
Seems to be unsupported in latest Mongoid:
Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
This worked instead:
Mongoid.purge!
Since this is for beginners, then following good practice, two identical files:
config/application.yml
config/application.example.yml
should be created and (both) discussed in the Configuration File section of the README.
Obviously, the example file (in source control) is visible to developers when they join a project; the other should be ignored by .gitignore.
Both should contain the text:
# Each developer, when first cloning the repository, should
# copy this file, removing '.example' from its name.
# This file (unless it's -.example.yml) should be listed in .gitignore
# to keep your settings secret!
Mac OS 10.7
Rails: 3.2
Ruby 1.9.3-p0 (rbenv)
rails new myapp -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-mongoid-devise-template.rb
Answering YES to everything except HAML, and option # 3 for Twitter Bootstrap.
It looks like problem is that the Mongo recipe deletes database.yml, but then the Devise recipe is looking for it.
Your bundle is updated! Use bundle show [gemname]
to see where a bundled gem is installed.
wizard Running 'after bundler' callbacks.
The template [https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-mongoid-devise-template.rb] could not be loaded. Error: You have already activated sprockets 2.1.2, but your Gemfile requires sprockets 2.1.3. Using bundle exec may solve this.
Rails 3.1's asset pipeline cannot properly compile css and js due to naming convention changes.
See application.html.haml
Generator creates:
= stylesheet_link_tag :all
= javascript_include_tag :defaults
For Rails 3.1 should read:
= stylesheet_link_tag "application"
= javascript_include_tag "application"
If this isn't modified, rails will try to find all.css and defaults.js, which of course don't exist.
Regarding accessing environment variables from db/seeds.rb, as well as in the section, Set Up a Database Seed File, of the README:
Since the Rails composer is using Figaro, why not follow the style of code, suggested by the Figaro gem's README, to access the environment variables? E.g.:
user = User.create! name: Figaro.env.admin_name
Hello!
Thanks for awesome tutorial! I tried to follow the manual steps for
https://github.com/RailsApps/rails3-mongoid-devise/wiki/Tutorial
but failed at "Adding RSpec for Unit Testing" / "Generate rspec" when running:
$ rails generate rspec:install
with
/Users/foo/.rvm/gems/ruby-1.9.2-p180@rails-devise-mongoid-app-test/gems/actionpack-3.1.0.rc4/lib/action_view/railtie.rb:34:in block (3 levels) in <class:Railtie>': undefined method
debug_rjs=' for ActionView::Base:Class (NoMethodError)
from /Users/foo/.rvm/gems/ruby-1.9.2-p180@rails-devise-mongoid-app-test/gems/actionpack-3.1.0.rc4/lib/action_view/railtie.rb:33:in each' from /Users/foo/.rvm/gems/ruby-1.9.2-p180@rails-devise-mongoid-app-test/gems/actionpack-3.1.0.rc4/lib/action_view/railtie.rb:33:in
block (2 levels) in class:Railtie'
The cause seems to be indicated by this commit which removes debug_rjs: rails/rails@d8f23ca
And here's the trivial change, once you found it, comment the debug_rjs away from config/environments/development.rb:
diff --git a/config/environments/development.rb b/config/environments/development.rb
index b0b4221..ae986ab 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -11,7 +11,7 @@ Kupla::Application.configure do
config.consider_all_requests_local = true
I guess this needs to be fixed in Rails.
Thought to let you know anyway.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.