How to generate a full_config for many_roles

23 views
Skip to first unread message

Helmut

unread,
Jan 4, 2011, 6:02:31 AM1/4/11
to Cream
Hello,
I want to generate a app with users, they can be assigned to more
roles. I am a rails newbie and i hope, that sombody else have used the
full_config generator for many_roles

very kind regards,
Helmut


i have inserted in the gemfile:

gem 'cream'
gem 'devise'
gem 'roles_active_record'

I have tried:

rails g cream:full_config --strategy many_roles

and get a error message after a wile;


===============================================================================

Some setup you must do manually if you haven't yet:

1. Setup default url options for your specific environment. Here is
an
example of development environment:

config.action_mailer.default_url_options = { :host =>
'localhost:3000' }

This is a required Rails configuration. In production it must be
the
actual host of your application

2. Ensure you have defined root_url to *something* in your config/
routes.rb.
For example:

root :to => "home#index"

3. Ensure you have flash messages in app/views/layouts/
application.html.erb.
For example:

<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>

===============================================================================
Configuring: devise mailer
Configuring: devise authentication filter
rails g devise:users --orm active_record --no-gems
run rails g devise:users --orm active_record --no-gems from
"."
[WARNING] You provided devise_for :users but there is no model User
defined in your application
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/lib/rspec/core/
backward_compatibility.rb:20:in `const_missing': uninitialized
constant User (NameError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/
lib/active_support/inflector/methods.rb:124:in `block in constantize'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/
lib/active_support/inflector/methods.rb:123:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/
lib/active_support/inflector/methods.rb:123:in `constantize'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.1.5/lib/
devise/mapping.rb:69:in `to'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.1.5/lib/
devise/mapping.rb:64:in `modules'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.1.5/lib/
devise/mapping.rb:73:in `strategies'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.1.5/lib/
devise.rb:281:in `block in configure_warden!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.1.5/lib/
devise.rb:280:in `each_value'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.1.5/lib/
devise.rb:280:in `configure_warden!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/devise-1.1.5/lib/
devise/rails/routes.rb:7:in `finalize_with_devise!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/application.rb:128:in `block in reload_routes!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/
lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/
lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/
lib/active_support/lazy_load_hooks.rb:26:in `on_load'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/application.rb:128:in `reload_routes!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/application.rb:120:in `block in routes_reloader'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/
lib/active_support/file_update_checker.rb:32:in `call'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/
lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/application/finisher.rb:51:in `block (2 levels) in
<module:Finisher>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/application/finisher.rb:52:in `call'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/application/finisher.rb:52:in `block in <module:Finisher>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/initializable.rb:25:in `instance_exec'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/initializable.rb:25:in `run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/initializable.rb:50:in `block in run_initializers'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/initializable.rb:49:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/initializable.rb:49:in `run_initializers'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/application.rb:134:in `initialize!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/application.rb:77:in `method_missing'
from C:/Dokumente und Einstellungen/rihe/My Documents/Aptana
Studio 3 Workspace/bc1/config/environment.rb:5:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/application.rb:103:in `require_environment!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/
rails/commands.rb:16:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
rails g cancan:config --orm active_record --no-gems
run rails g cancan:config --orm active_record --no-gems from
"."

Kristian Mandrup

unread,
Jan 4, 2011, 6:25:31 AM1/4/11
to rails...@googlegroups.com
Hi Helmut,

All you need to do is to insert the following in the Gemfile

> gem 'cream'


Then run bundle install and then the full_config generator. I have been notified of some errors in the latest version which I will fix today. I also want to make some improvements in general to make it more flexible and generic.
The next release should contain these fixes and enhancements.
Stay tuned.

Kristian

Helmut

unread,
Jan 4, 2011, 7:49:13 AM1/4/11
to Cream
Hello Kristian,
Thank you for your reply.

Bewile i have tried to run the followin commands:

rails g devise User
rails g cream:full_config --strategy many_roles

The generator adds a line in the File app\models\user.rb generating an
error! Is there smoething wrong with my input?

Kind regards,
Helmut


class User < ActiveRecord::Base
include Roles::ActiveRecord
strategy :many_roles, <<<<-------- this line does not work!

include Roles::ActiveRecord
strategy :many_roles
valid_roles_are :admin, :guest
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model

attr_accessible :email, :password, :password_confirmation, :remember_me
end

Kristian Mandrup

unread,
Jan 4, 2011, 9:35:50 AM1/4/11
to rails...@googlegroups.com
I am still in the process of updating Cream to be more stable and also some enhancements.

The particular problem you have is related to 'roles_active_record'. Check out the specs in that project.

$ rspec spec/roles_active_record/strategy/multi/many_roles_spec.rb

This spec uses and tests the fixture file 'many_roles_setup.rb'

class User < ActiveRecord::Base
include Roles::ActiveRecord

strategy :many_roles

valid_roles_are :admin, :guest, :user
end

To run specs with rspec, first do:

$ gem install database_cleaner rspec

I get:

27 examples, 0 failures

So the code should work!?

You should have a gem 'roles_active_record' in your rails app Gemfile after Cream has been installed (via the full_config generator). Otherwise insert it manually for now.

Kristian

Kristian Mandrup

unread,
Jan 4, 2011, 9:41:28 AM1/4/11
to rails...@googlegroups.com
I just pushed the latest version to the refactor branch

https://github.com/kristianmandrup/cream/tree/refactor

Try:

$ git clone https://github.com/kristianmandrup/cream
$ cd cream
$ git checkout refactor
$ pwd

Then go into your Rails app in the Gemfile and set the path

gem 'cream', :path => 'whatever pwd returned'

then

$ bundle install

Then you will be running cream from your local clone and you can debug from there and help make it work ;)
Thanks.

Kristian


On Jan 4, 2011, at 1:49 PM, Helmut wrote:

Kristian Mandrup

unread,
Jan 4, 2011, 10:16:06 AM1/4/11
to rails...@googlegroups.com
I just noticed that you used the strategy "many_role" which is invalid. It should be "many_roles". The latest refactor branch now contains validation logic to catch this and signal this an error, listing the valid strategies...

On Jan 4, 2011, at 1:49 PM, Helmut wrote:

Kristian Mandrup

unread,
Jan 4, 2011, 11:10:00 AM1/4/11
to rails...@googlegroups.com
Hi Helmut,

After a major refactoring effort all day, the latest releases of cream (0.8.6) and roles_active_record (0.4.4) now seem to work as expected and have a much more elegant, stable and flexible design to boot :)
Note: You shouldn't have to run any devise generators before running full_config.

Hope it works out now...

Kristian


On Jan 4, 2011, at 1:49 PM, Helmut wrote:

George Precious

unread,
Feb 11, 2014, 4:08:23 AM2/11/14
to rails...@googlegroups.com
Hi Kristian, 
   when i try to use rails g cream:full_config, this is the error i get /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require': no such file to load -- rails_artifactor (LoadError), please help as i have tried everything i could without progress. 

Kristian Mandrup

unread,
Feb 11, 2014, 5:14:08 AM2/11/14
to rails...@googlegroups.com
Hi George,

I would recommend you not to use Cream. It is a completely outdated project and I'm not maintaining it anymore. I'm on Node.js and Angular.js now, with Mongo DB or Firebase as backend. I'm pretty much done with Rails...
However, if you like the ideas in Cream, you are free to use some of the ideas and code for your own similar project. 
As you can see, rails_artifactor is one of my many gems:


It looks like it isn't being correctly picked up in Gemfile. Try adding it there as a dependency.

For a top notch, better designed Authorization solution, I recommend that you check out one of my latest projects: https://github.com/kristianmandrup/authorize-mw

OK, it is written in LiveScript (my new love!) - but you could port it to Ruby/Rails for sure. It gives you most of what I was trying to achieve with various gems in my previous projects such as Cream and CanTango etc.
Have a blast! Good luck!

Kristian




--
You received this message because you are subscribed to the Google Groups "Cream" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails-cream...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

George Precious

unread,
Feb 11, 2014, 5:40:18 AM2/11/14
to rails...@googlegroups.com
Thanks for the advise, i would look at that in other upcoming projects, i have never taken a look at Node.js so i am hardly sure i can port it and i am fairly new to rails as well, but please could you help me with this? 
i saw on git that one had to place this 

hi collin, sorry where do i place this configuration?

require 'generators/cream/full_config/full_config_generator'

class Cream::Generators::FullConfigGenerator
def self.source_root
File.join File.dirname(FILE), "..", "..", "..", ".."
end
end

so as to avoid the template part error. Please could you tell me where exactly it should reside?

Kristian Mandrup

unread,
Feb 11, 2014, 9:35:43 AM2/11/14
to rails...@googlegroups.com
Hi George,

What exactly are you trying to achieve? I assume you want to setup some Role based Authorization and Authentication using CanCan and Devise. Rails has come a long way since those times back in 2009-2010 I would think.
Try instead to find some updated blog posts on these subjects. I'm pretty sure that CanCan and Devise are no longer the way to go.

I would also say, that learning LiveScript with JsClass and Mocha, using Express server and Angular with Bootstrap is the way forward. Rails 4 has just as steep a learning curve and is very much "old school" by now. 
It is not the way of the future anymore... so time to change horses if you haven't gone too far down this rabbit hole yet (psychology of previous investment). The technologies change quickly these days...
But perhaps you are in a project that is investing in these old school techs and so have no choice.
In any case, I would advise against trying to run a generator that magically sets up your whole auth environment to your satisfaction. It was a "pipe dream"...
You can look at CanTango instead or some similar projects.



As you can see... not easy with all this "magic", especially without a maintainer to follow up on issues.

Check here:


I would recommend




I'm sure you can find a lot of community support behind these projects and much more up to date projects ;)

Good luck!

Kris


 
Reply all
Reply to author
Forward
0 new messages