cristie
1
Hi all.
We have been trying to do a custom layout for special user’s via
something like this:
class ProductsController < ApplicationController
def show
products_layout
@product = Product.find(params[:id])
end
private def products_layout
layout ‘special’ if @current_user.special?
layout ‘not_special’ unless @current_user.special?
end
end
We got a ‘no such method error’ on layout.
via the url below:
we know that below is the right way to do it but my question is
From a ruby perspective what is ‘layout’ if it is not a method?
class ProductsController < ApplicationController
layout :products_layout
def show
@product = Product.find(params[:id])
end
private def products_layout
@current_user.special? ? “special” : “products”
end
end
cristie
2
Cris S. wrote:
Hi all.
We have been trying to do a custom layout for special user’s via
something like this:
class ProductsController < ApplicationController
def show
products_layout
@product = Product.find(params[:id])
end
private def products_layout
layout ‘special’ if @current_user.special?
layout ‘not_special’ unless @current_user.special?
end
end
We got a ‘no such method error’ on layout.
via the url below:
Layouts and Rendering in Rails — Ruby on Rails Guides
we know that below is the right way to do it
Then do it that way.
but my question is
From a ruby perspective what is ‘layout’ if it is not a method?
Of course it’s a method. It’s a class method in the controller. So to
call it from within an instance method, you’d have to call
self.class.layout.
class ProductsController < ApplicationController
layout :products_layout
def show
@product = Product.find(params[:id])
end
private def products_layout
@current_user.special? ? “special” : “products”
end
end
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
cristie
3
Thanks Marnen. I have replied to thank you three times and none of them
seem to post…
Cris