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

The theme selector method is not invoked in some situations. #59

Open
jarl-dk opened this issue Jun 10, 2012 · 5 comments
Open

The theme selector method is not invoked in some situations. #59

jarl-dk opened this issue Jun 10, 2012 · 5 comments

Comments

@jarl-dk
Copy link

jarl-dk commented Jun 10, 2012

I have theme_resolver method like this:

class MyController < ApplicationController
  theme :theme_resolver
  # ...
  def show
    @current_user = ...
  end

private
  def theme_resolver
    @current_user && @current_user.theme # or anything else that return a string. 
  end
end

The first time theme_resolver is invoked is prior to the action, so it returns nil.
Next time it is invoked is at the time of render, at this time it is invoked as a method included in the my ActionView view. At this time the line (in common_methods.rb:12)

self.respond_to?(@theme_name, true) ? self.send(@theme_name) : @theme_name.to_s

returns nil, because self.respond_to?(@theme_name, true) evaluates to false because the theme_resolver is not member of the view (it's a member of the controller) so the theme_resolver is not invoked at all.
I suggest changing that line to something like

self.is_a? ActionView ? (self.controller.respond_to?(@theme_name, true) ? self.controller.send(@theme_name) : @theme_name.to_s)
  : (self.respond_to?(@theme_name, true) ? self.send(@theme_name) : @theme_name.to_s)

or something like that.

Meanwhile I have to invoke (as a workaround)

theme theme_name

to set and cache the theme_name before my action method reach the render code.

Jarl

@lucasefe
Copy link
Owner

Jarl, thanks fo the detailed response.

So you are calling the :theme method from the view? What are you trying to achieve? Hit me on freenode, #rubysur.

@lucasefe
Copy link
Owner

Btw, you can declare the :theme method as a helper_method and have it available on the view (if that's what you want) without having to touch the TFR codebase.

@jarl-dk
Copy link
Author

jarl-dk commented Jun 14, 2012

OK, I'll try to catch you later on IRC, what nick?

@lucasefe
Copy link
Owner

lucasefe

On Thu, Jun 14, 2012 at 9:54 AM, Jarl Friis <
[email protected]

wrote:

OK, I'll try to catch you later on IRC, what nick?


Reply to this email directly or view it on GitHub:
#59 (comment)

@lucasefe
Copy link
Owner

Ok, this is valid issue. I'll start working on fix. Good catch.

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