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

undefined method `refinery_user?' when use with ActiveAdmin #1804

Closed
harley opened this issue Jul 9, 2012 · 15 comments
Closed

undefined method `refinery_user?' when use with ActiveAdmin #1804

harley opened this issue Jul 9, 2012 · 15 comments

Comments

@harley
Copy link

harley commented Jul 9, 2012

Basically if you include 'activeadmin' gem, when rendering the view containing a refinery_user? call, the method is recognized. This is probably due to the incompatibility between ActiveAdmin's fancy ActiveAdmin.routes(self) in routes.rb (https://github.com/gregbell/active_admin/blob/master/lib/active_admin/application.rb#L199) vs mount Refinery::Core::Engine, :at => '/'

Steps:

rvm use --create ruby-1.9.3@refinery
gem install bundler --pre
gem install refinerycms
rails new rickrockstar -m http://refinerycms.com/t/2.0.5
# add 'activeadmin' gem to Gemfile
bundle
rails g active_admin:install
rake db:migrate
rails s
# go to http://localhost:3000 and create an admin user
# log out and Ctrl-C to exit server. may need to do this because otherwise refinery_user? may have been loaded via /refinery after signing up
rails s
# open http://localhost:3000 again

Error

NoMethodError in Refinery/pages#home

Showing /Users/sandbox/.rvm/gems/ruby-1.9.3-p194@refinery/gems/refinerycms-core-2.0.5/app/views/refinery/_site_bar.html.erb where line #1 raised:

undefined method `refinery_user?' for #<#<Class:0x00000100c70c30>:0x00000100ae7940>
Extracted source (around line #1):

1: <% if refinery_user? && "#{controller_name}##{action_name}" != 'pages#preview' %>
2:   <% unless admin? # all required JS included by backend. %>
3:     <% content_for :stylesheets, stylesheet_link_tag('refinery/site_bar') unless !!local_assigns[:exclude_css] %>
4:     <%= yield(:stylesheets) unless local_assigns[:head] or local_assigns[:exclude_css] %>
Trace of template inclusion: /Users/sandbox/.rvm/gems/ruby-1.9.3-p194@refinery/gems/refinerycms-core-2.0.5/app/views/layouts/application.html.erb

Rails.root: /Users/sandbox/code/examples/rickrockstar

The above example app is here https://github.com/harleyttd/rickrockstar

I just realized I should have reproduced with the edge version. Hope it still helps given it's the latest release and I didn't find any past issue mentioning this.

Thanks

@parndt
Copy link
Member

parndt commented Jul 9, 2012

Hello,

Thanks for this. To work around the issue you can override the site bar file using rake refinery:override view=refinery/_site_bar and replace the top line with this:

<% if refinery_user_signed_in? && current_refinery_user.has_role?(:refinery) && "#{controller_name}##{action_name}" != 'pages#preview' %>

@parndt
Copy link
Member

parndt commented Jul 9, 2012

Ah! Alternatively place this in your ApplicationController:

include Refinery::AuthenticatedSystem

@parndt
Copy link
Member

parndt commented Jul 9, 2012

Here's my ApplicationController (well, actually yours as I cloned your project) which works:

class ApplicationController < ActionController::Base
  protect_from_forgery

  include Refinery::AuthenticatedSystem
end

@parndt
Copy link
Member

parndt commented Jul 9, 2012

I'm not entirely sure why but from what I can gather (being that you can put helper :refinery_user? instead of include Refinery::AuthenticatedSystem and it still works) ActiveAdmin is doing something with ApplicationController which means that Refinery thinks it can't use these methods as helper methods.

@harley
Copy link
Author

harley commented Jul 9, 2012

thanks for being lightning fast at responding again and with effective workarounds! refinery_user? is in a few other partials in refinery besides site_bar..

using helper_method :refinery_user? (not helper) works great for the sample app and my production app. that way overtime i may find out if refinery_user? is the only method affected

@parndt
Copy link
Member

parndt commented Jul 9, 2012

Yeah helper_method sorry!

@harley
Copy link
Author

harley commented Jul 9, 2012

np it was understood. by the way this is a better link to the potential culprit method in ActiveAdmin in case it's obvious to some eyes something is missing in there (such as dealing with other mounted engines?). I tried moving the (priority) order of ActiveAdmin.routes(self) and mount Refinery::Core::Engine, :at => '/' lines in routes.rb but doesnt help. i'm not familiar with router code so i don't have any clue here yet: https://github.com/gregbell/active_admin/blob/master/lib/active_admin/router.rb#L8

@parndt
Copy link
Member

parndt commented Jul 9, 2012

I wonder if @gregbell has any insight into this that he could share? :-)

@harley
Copy link
Author

harley commented Jul 9, 2012

hope @pcreux doesn't mind being mentioned here as well :)

@gregbell
Copy link

gregbell commented Jul 9, 2012

Hi Guys, I had a brief chance to look into this today.

It's not entirely clear what the source of the bug is, but it seems to be related to the use of Devise in both projects. I'm swamped today, but I hope to get a chance to take a look at it over the next couple of days. I'll report back on what I find.

@harley
Copy link
Author

harley commented Jul 13, 2012

thanks for looking into it. in case it helps, i do have other devise routes defined in my routes file, such as devise_for :students and devise_for :teachers, but they are working fine with refinerycms. they also work fine with activeadmin by themselves. now when i combine them, the only issue so far that i need to manually add helper_method :refinery_user? as mentioned above

(Refinery::AuthenticatedSystem module's included hook does include this helper_method call: https://github.com/resolve/refinerycms/blob/master/authentication/lib/refinery/authenticated_system.rb#L68)

@abhijitsinha
Copy link

Hi, me too facing the same issue when i tried integrating both refinery and activeadmin together into an app, while individually both ran fine. Is there anything to guide me par this issue or cuztomization i need to do to make this two gems work together? Hoping a timely reply, thanks.

@parndt
Copy link
Member

parndt commented Aug 26, 2012

The workaround solution is contained further up - aka in your ApplicationController class put:

helper_method :refinery_user?

@amacneil
Copy link

This happens for me when integrating Refinery with Spree 1.2 as well. I've implemented the fix above in my example app (https://github.com/adrianmacneil/refinery_spree), no idea what is causing it though.

@robyurkowski
Copy link
Contributor

Seeing as we have a fix, and this depends on active_admin being present, I'm going to mark this as closed. Give me your objections and I will happily consider them.

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

No branches or pull requests

6 participants