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

Cancan usage? #31

Closed
sonnymai opened this issue Sep 5, 2011 · 5 comments
Closed

Cancan usage? #31

sonnymai opened this issue Sep 5, 2011 · 5 comments

Comments

@sonnymai
Copy link

sonnymai commented Sep 5, 2011

I get this error when trying to use cancan and attempt to browse images in ckeditor:

Expected <app_path>/app/models/ckeditor/picture.rb to define Picture

I have placed this in myapplication_controller.rb

  protected
    # Cancan example
    def ckeditor_authenticate
      authorize! action_name, @asset
    end

    # Set current_user as assetable
    def ckeditor_before_create_asset(asset)
      asset.assetable = current_user
      return true
    end

And this in ability.rb

can [:index], Picture if user.role? :user

I suspect it could be something to do with the namespaced controller/models?

@galetahub
Copy link
Owner

Try this:

can [:index], Ckeditor::Picture if user.role? :user

@sonnymai
Copy link
Author

sonnymai commented Sep 5, 2011

Thanks for the suggestion. I had tried that before and unfortunately that doesn't work. I just get CanCan::AccessDenied when using that.

heres some lines from the stacktrace:

activesupport (3.1.0) lib/active_support/dependencies.rb:490:in `load_missing_constant'
activesupport (3.1.0) lib/active_support/dependencies.rb:181:in `block in const_missing'
activesupport (3.1.0) lib/active_support/dependencies.rb:179:in `each'
activesupport (3.1.0) lib/active_support/dependencies.rb:179:in `const_missing'
activesupport (3.1.0) lib/active_support/dependencies.rb:501:in `load_missing_constant'
activesupport (3.1.0) lib/active_support/dependencies.rb:181:in `block in const_missing'
activesupport (3.1.0) lib/active_support/dependencies.rb:179:in `each'
activesupport (3.1.0) lib/active_support/dependencies.rb:179:in `const_missing'
app/models/ability.rb:99:in `initialize'
cancan (1.6.5) lib/cancan/controller_additions.rb:349:in `new'
cancan (1.6.5) lib/cancan/controller_additions.rb:349:in `current_ability'
cancan (1.6.5) lib/cancan/controller_additions.rb:330:in `authorize!'
app/controllers/application_controller.rb:17:in `ckeditor_authenticate'
activesupport (3.1.0) lib/active_support/callbacks.rb:430:in `_run__2103710711640583003__process_action__688618921792957714__callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'

@adamtao
Copy link

adamtao commented Nov 22, 2011

I had the same issue. I figured out that the @asset in the callback is Nil at some point. (Perhaps it creates a dummy asset as a placeholder for the upload link--just guessing.) Anyway, if you just skip the authorize! method if the @asset is Nil, then it works:

  protected
    # Cancan example
    def ckeditor_authenticate
      if @asset
        authorize! action_name, @asset
      end
    end

Also, be sure your ability.rb file uses the suggestion from galetahub above:

can [:index], Ckeditor::Picture if user.role? :user

or

can [:index], Ckeditor::Asset if user.role? :user

@barmstrong
Copy link

I ran into this error also.

For me what fixed it was removing #{Rails.root}/app/models/ckeditor from config.autoload_paths in application.rb

@galetahub
Copy link
Owner

Added support for cancan integration in this commit d336964

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

4 participants