Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninitialized constant Control #5

Closed
DonGiulio opened this issue Jun 6, 2013 · 4 comments
Closed

uninitialized constant Control #5

DonGiulio opened this issue Jun 6, 2013 · 4 comments

Comments

@DonGiulio
Copy link

Hello,

I'm using:
devise (2.2.4)
milia (0.3.30)
Rails 3.2.12
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]

I've tried to follow your tutorial, but upon user creation I get:

uninitialized constant Control

below the log:

Started POST "/users" for 127.0.0.1 at 2013-06-06 12:02:49 +0200
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8uZpO5HRLvkhxsrhUfZzq3i710po/AnngI1VZJeOZ70=", "user"=>{"username"=>"", "email"=>"[cut]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.1ms) begin transaction
User Exists (0.4ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = '[cut]' LIMIT 1
SQL (0.7ms) INSERT INTO "tenants" ("created_at", "name", "tenant_id", "updated_at") VALUES (?, ?, ?, ?) ["created_at", Thu, 06 Jun 2013 12:02:49 CEST +02:00], ["name", :username], ["tenant_id", nil], ["updated_at", Thu, 06 Jun 2013 12:02:49 CEST +02:00] rollback transaction
Completed 500 Internal Server Error in 70ms

NameError (uninitialized constant Control):
milia (0.3.30) lib/milia/base.rb:61:in block in acts_as_universal' activesupport (3.2.8) lib/active_support/callbacks.rb:440:in_run__3560432618853441863__save__2851447896423817079__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in __run_callback' activesupport (3.2.8) lib/active_support/callbacks.rb:385:in_run_save_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in run_callbacks' activerecord (3.2.8) lib/active_record/callbacks.rb:264:increate_or_update'
activerecord (3.2.8) lib/active_record/persistence.rb:84:in save' activerecord (3.2.8) lib/active_record/validations.rb:50:insave'
activerecord (3.2.8) lib/active_record/attribute_methods/dirty.rb:22:in save' activerecord (3.2.8) lib/active_record/transactions.rb:241:inblock (2 levels) in save'
activerecord (3.2.8) lib/active_record/transactions.rb:295:in block in with_transaction_returning_status' activerecord (3.2.8) lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction'
activerecord (3.2.8) lib/active_record/transactions.rb:208:in transaction' activerecord (3.2.8) lib/active_record/transactions.rb:293:inwith_transaction_returning_status'
activerecord (3.2.8) lib/active_record/transactions.rb:241:in block in save' activerecord (3.2.8) lib/active_record/transactions.rb:252:inrollback_active_record_state!'
activerecord (3.2.8) lib/active_record/transactions.rb:240:in save' devise (2.2.4) app/controllers/devise/registrations_controller.rb:15:increate'
actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in send_action' actionpack (3.2.8) lib/abstract_controller/base.rb:167:inprocess_action'
actionpack (3.2.8) lib/action_controller/metal/rendering.rb:10:in process_action' actionpack (3.2.8) lib/abstract_controller/callbacks.rb:18:inblock in process_action'
activesupport (3.2.8) lib/active_support/callbacks.rb:458:in `_run__4479752414565192415__process_action__2670286493514513815__callbacks'
[cut].....

@DonGiulio
Copy link
Author

I managed to fix this by changing the file:

lib/milia/base.rb:61

from

raise ::Control::InvalidTenantAccess unless obj.tenant_id.nil?

to

raise ::Milia::Control::InvalidTenantAccess unless obj.tenant_id.nil?

I guess the exceptions weren't tested. I reckon all the "::Control::" lines should be updated with "::Milia::Control".

Please advise

thanks a lot,
Giulio

@DonGiulio
Copy link
Author

ok, but now I can't understand why I get that exception.

I put the hooks in the user model like follows:

class User < ActiveRecord::Base

before_save :createTenant
after_save :signupTenant

Include default devise modules. Others available are:

:token_authenticatable, :confirmable,

:lockable, :timeoutable and :omniauthable

devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

acts_as_universal_and_determines_account

Setup accessible (or protected) attributes for your model

attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :tenant

attr_accessible :title, :body

private
def createTenant
logger.debug "creating user '#{username}'"
self.tenant = Tenant.create_new_tenant({:name => self.email })
logger.debug "new tenant created : '#{self.tenant.to_yaml}'"
end

def signupTenant
Tenant.tenant_signup(user, tenant, other)
end
end

And it seems that the:

acts_as_universal

method, called by:

acts_as_universal_and_determines_account

requires the user NOT to have a tenant_id, which is inserted by before_save hook.

I'm confused here, am I using the right hooks?

thanks a lot.

@dsaronin
Copy link
Contributor

dsaronin commented Jun 6, 2013

Hi thanks for ::Milia::Control::Exception info. I'll need to update the gem.

You should NOT have those two hooks (before_save/after_save) in your user
model.
You should also not have the two private methods createTenant, signupTenant
in your User model.

Please read the section in the readme doc titled: Tenant pre-processing
hooks

A tenant == an organization; users == members of the organization. Only
organizations sign up for new tenants, not members (users). The very first
user of an organization, let's call him the Organizer, is the one
responsible for initiating the organizational signup and becomes the first
member (user) of the organization (tenant). Thereafter, members only obtain
entry to the organization (tenant) by invitation. New tenants are not
created for every new user.

On Thu, Jun 6, 2013 at 6:54 AM, DonGiulio notifications@github.com wrote:

ok, but now I can't understand why I get that exception.

I put the hooks in the user model like follows:

class User < ActiveRecord::Base

before_save :createTenant
after_save :signupTenant

Include default devise modules. Others available are:

:token_authenticatable, :confirmable,

:lockable, :timeoutable and :omniauthable

devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

acts_as_universal_and_determines_account

Setup accessible (or protected) attributes for your model

attr_accessible :email, :password, :password_confirmation, :remember_me,
:username, :tenant

attr_accessible :title, :body

private
def createTenant
logger.debug "creating user '#{username}'"
self.tenant = Tenant.create_new_tenant({:name => self.email })
logger.debug "new tenant created : '#{self.tenant.to_yaml}'"
end

def signupTenant
Tenant.tenant_signup(user, tenant, other)
end
end

And it seems that the:

acts_as_universal

method, called by:

acts_as_universal_and_determines_account

requires the user NOT to have a tenant_id, which is inserted by
before_save hook.

I'm confused here, am I using the right hooks?

thanks a lot.


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-19046423
.

@dsaronin
Copy link
Contributor

The ::Control:: bug has been fixed in 0.3.38 of milia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants