GithubHelp home page GithubHelp logo

railsapps / rails3-mongoid-devise Goto Github PK

View Code? Open in Web Editor NEW
402.0 402.0 74.0 478 KB

An example Rails 3.2 app with Mongoid for data, Devise for authentication.

Home Page: http://railsapps.github.io/

Ruby 96.37% JavaScript 1.20% CoffeeScript 0.43% CSS 2.00%

rails3-mongoid-devise's People

Contributors

danielkehoe avatar fortuity avatar jcasimir avatar nrser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rails3-mongoid-devise's Issues

ExecJS::RuntimeUnavailable when using the template + solution

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

Mongoid.master

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

Want to make admin to create other users and edit other users account

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?

FactoryGirl fragile on user model

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?

Problem with DatabaseCleaner, and solution

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.

'bundle exec rake db:migrate from "."' fails

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)

Missing newline in Gemfile at line 48

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

rails3

when i m editing index.html.erb in notepad and try to save ,its the message"this file is opened in another program"

'Login' and 'Logout' used inconsistently along with 'Sign in' and 'Sign out'

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.

Email validation in user model

I noticed one failing test in user_spec.rb when running 'rspec spec' for the first time:

Failures:

  1. User should reject invalid email addresses
    Failure/Error: invalid_email_user.should_not be_valid
    expected valid? to return false, got true

    ./spec/models/user_spec.rb:35:in `block (3 levels) in <top (required)>'

    ./spec/models/user_spec.rb:33:in`each'

    ./spec/models/user_spec.rb:33:in `block (2 levels) in <top (required)>'

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

Cant setup new user db:seed

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)

"db_name must be a string or symbol" on rake assets:precompile

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.

Fail with rolify/cancan option.

    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)>'

README doesn't need to mention `db:test:prepare`

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.

Unclear instruction for code modification to create a default user

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!

In home_Controller code change

In home_controller.rb
index method

@user=User.all.to_a from @user=User.all (According to mongoid documentation) , otherwise user will get error that user is a nil class.

BSON::InvalidObjectId in UsersController#show accessing users/1 after login

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"

app_name undefined in tutorial

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.

Update docs regarding mongoid, similar to rails3-mongoid-omniauth

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>

Mongoid 2.3.0 requires MongoDB 2.0

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?

Can't get cucumber tests to pass

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:inclick_button'
./features/step_definitions/web_steps.rb:53:in /^(?:|I )press "([^"]*)"$/' features/users/user_edit.feature:8:inWhen I sign in as "[email protected]/please"'
Then I should be signed in

README should caveat `rake cucumber` won't run @wip cukes

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).'

Should include Application.example.yml file

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!

Sprockets version

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.

Generator creates incorrect stylesheet and js link references for Rails 3.1

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.

Use Figaro to access environment variables

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

Generate rspec failing with Rails 3.1.0.rc4

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 methoddebug_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:inblock (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

Show full error reports and disable caching

config.consider_all_requests_local = true

  • config.action_view.debug_rjs = true
  • #config.action_view.debug_rjs = true
    config.action_controller.perform_caching = false

Don't care if the mailer can't send

I guess this needs to be fixed in Rails.

Thought to let you know anyway.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.