lucasefe / themes_for_rails

Theme Support for Rails 3
This very same page :)
MIT License
308 stars 102 forks source link

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

Open jarl-dk opened 12 years ago

jarl-dk commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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

lucasefe commented 12 years ago

lucasefe

On Thu, Jun 14, 2012 at 9:54 AM, Jarl Friis < reply@reply.github.com

wrote:

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


Reply to this email directly or view it on GitHub: https://github.com/lucasefe/themes_for_rails/issues/59#issuecomment-6327242

lucasefe commented 12 years ago

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