Pierre Valade | 31 Aug 19:33

[RailsFr] Rails layout


Bonjour,

J'utilise dans un même controller deux layouts différents.

J'aimerais donc faire, d'après la doc,

  layout 'public', :only => [:new, :create, :forgot_password]
  layout 'home', :only => [:show, :edit]

Mais cela ne marche pas. En effet, seule la dernière ligne est prise
en compte.

Y a-t-il une solution pour utiliser deux layouts différents dans un
même controller ?

Je vous remercie par avance,

Pierre Valade
--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse railsfrance@...
Pour résilier votre abonnement envoyez un e-mail à l'adresse railsfrance-unsubscribe@...
-~----------~----~----~----~------~----~------~--~---

Tranquiliste | 31 Aug 22:35

[RailsFr] Re: Rails layout


Bonjour,

Je n'ai jamais testé mails il me semble que tu peux executer une
methode pour deterniner ton layout du style

layout :quel_layout

def quel_layout
 if condition
   'public'
 else
  'home'
end
end

Il faut que tu trouves la condition qui différencie l'action dans
laquelle tu te trouves
--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse railsfrance@...
Pour résilier votre abonnement envoyez un e-mail à l'adresse railsfrance-unsubscribe@...
-~----------~----~----~----~------~----~------~--~---

Pierre Valade | 1 Sep 01:00

[RailsFr] Re: Rails layout


Oui, c'est la solution de dernier recours que je voulais pas
utiliser :)

On 31 août, 22:35, Tranquiliste <nico...@...> wrote:
> Bonjour,
>
> Je n'ai jamais testé mails il me semble que tu peux executer une
> methode pour deterniner ton layout du style
>
> layout :quel_layout
>
> def quel_layout
>  if condition
>    'public'
>  else
>   'home'
> end
> end
>
> Il faut que tu trouves la condition qui différencie l'action dans
> laquelle tu te trouves
--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse railsfrance@...
Pour résilier votre abonnement envoyez un e-mail à l'adresse railsfrance-unsubscribe@...
-~----------~----~----~----~------~----~------~--~---

Michel Belleville | 1 Sep 07:33
Gravatar

[RailsFr] Re: Rails layout

Tiens, au fait, qu'en dit la doc ?...

Conditional layouts

If you have a layout that by default is applied to all the actions of a controller, you still have the option of rendering a given action or set of actions without a layout, or restricting a layout to only a single action or a set of actions. The :only and :except options can be passed to the layout call. For example:

class WeblogController < ActionController::Base
layout "weblog_standard", :except => :rss

# ...

end

This will assign "weblog_standard" as the WeblogController's layout except for the rss action, which will not wrap a layout around the rendered view.

Both the :only and :except condition can accept an arbitrary number of method references, so #:except => [ :rss, :text_only ] is valid, as is :except => :rss.

Using a different layout in the action render call

If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above. Sometimes you'll have exceptions where one action wants to use a different layout than the rest of the controller. You can do this by passing a :layout option to the render call. For example:

class WeblogController < ActionController::Base
layout "weblog_standard"

def help
render :action => "help", :layout => "help"
end
end

This will render the help action with the "help" layout instead of the controller-wide "weblog_standard" layout.

--
Michel Belleville

--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse railsfrance-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Pour résilier votre abonnement envoyez un e-mail à l'adresse railsfrance-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
-~----------~----~----~----~------~----~------~--~---

Pierre Valade | 1 Sep 10:11

[RailsFr] Re: Rails layout


Merci Michel. Donc effectivement aucune solution pour faire simplement
ce que je voulais :)

On 1 sep, 07:33, "Michel Belleville" <michel.bellevi...@...>
wrote:
> Tiens, au fait, qu'en dit la doc ?...
>
> Conditional layouts
>
> If you have a layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>that
> by default is applied to all the actions of a controller, you still
> have the option of rendering a given action or set of actions without a
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>,
> or restricting a
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>to
> only a single action or a set of actions. The
> :only and :except options can be passed to the
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>call.
> For example:
>
>   class WeblogController < ActionController::Base
>     layout "weblog_standard", :except => :rss
>
>     # ...
>
>   end
>
>  This will assign "weblog_standard" as the WeblogController's
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>except
> for the
> rss action, which will not wrap a
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>around
> the rendered view.
>
> Both the :only and :except condition can accept an arbitrary number of
> method references, so #:except => [ :rss, :text_only ] is valid, as is :except
> => :rss.
> Using a different
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>in
> the action render call
>
> If most of your actions use the same
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>,
> it makes perfect sense to define a controller-wide
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>as
> described above. Sometimes you'll have exceptions where one action
> wants
> to use a different
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>than
> the rest of the controller. You can do this by passing a
> :layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>option
> to the
> render call. For example:
>
>   class WeblogController < ActionController::Base
>     layout "weblog_standard"
>
>     def help
>       render :action => "help", :layout => "help"
>     end
>   end
>
>  This will render the help action with the "help"
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>instead
> of the controller-wide "weblog_standard"
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>.
>
> --
> Michel Belleville
--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse railsfrance@...
Pour résilier votre abonnement envoyez un e-mail à l'adresse railsfrance-unsubscribe@...
-~----------~----~----~----~------~----~------~--~---

Michel Belleville | 1 Sep 10:28
Gravatar

[RailsFr] Re: Rails layout

Ca dépend de ce que tu veux dire par "simplement". Indiquer dans le render de l'action quel layout utiliser, je trouve ça plutôt simple...

2008/9/1 Pierre Valade <pierre.valade <at> gmail.com>

Merci Michel. Donc effectivement aucune solution pour faire simplement
ce que je voulais :)

On 1 sep, 07:33, "Michel Belleville" <michel.bellevi... <at> gmail.com>
wrote:
> Tiens, au fait, qu'en dit la doc ?...
>
> Conditional layouts
>
> If you have a layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>that
> by default is applied to all the actions of a controller, you still
> have the option of rendering a given action or set of actions without a
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>,
> or restricting a
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>to
> only a single action or a set of actions. The
> :only and :except options can be passed to the
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>call.
> For example:
>
>   class WeblogController < ActionController::Base
>     layout "weblog_standard", :except => :rss
>
>     # ...
>
>   end
>
>  This will assign "weblog_standard" as the WeblogController's
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>except
> for the
> rss action, which will not wrap a
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>around
> the rendered view.
>
> Both the :only and :except condition can accept an arbitrary number of
> method references, so #:except => [ :rss, :text_only ] is valid, as is :except
> => :rss.
> Using a different
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>in
> the action render call
>
> If most of your actions use the same
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>,
> it makes perfect sense to define a controller-wide
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>as
> described above. Sometimes you'll have exceptions where one action
> wants
> to use a different
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>than
> the rest of the controller. You can do this by passing a
> :layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>option
> to the
> render call. For example:
>
>   class WeblogController < ActionController::Base
>     layout "weblog_standard"
>
>     def help
>       render :action => "help", :layout => "help"
>     end
>   end
>
>  This will render the help action with the "help"
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>instead
> of the controller-wide "weblog_standard"
> layout<http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>.
>
> --
> Michel Belleville




--
Michel Belleville

--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse railsfrance <at> googlegroups.com
Pour résilier votre abonnement envoyez un e-mail à l'adresse railsfrance-unsubscribe <at> googlegroups.com
-~----------~----~----~----~------~----~------~--~---

Guillaume Betous | 1 Sep 14:13
Gravatar

[RailsFr] Re: Rails layout


je n'ai pas vu le screencast, mais le sujet peut peut-etre se prêter à
ton pb : http://railscasts.com/episodes/125-dynamic-layouts

gUI

--

-- 
Pour la santé de votre ordinateur, préférez les logiciels libres.
Lire son mail : http://www.mozilla-europe.org/fr/products/thunderbird/
Browser le web : http://www.mozilla-europe.org/fr/products/firefox/
Suite bureautique : http://fr.openoffice.org/

--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse railsfrance@...
Pour résilier votre abonnement envoyez un e-mail à l'adresse railsfrance-unsubscribe@...
-~----------~----~----~----~------~----~------~--~---

Pierre Valade | 1 Sep 15:46

[RailsFr] Re: Rails layout


Oui, je suis d'accord (mais fainéant :)
Merci à vous deux pour les astuces.

On 1 sep, 10:28, "Michel Belleville" <michel.bellevi...@...>
wrote:
> Ca dépend de ce que tu veux dire par "simplement". Indiquer dans le render
> de l'action quel layout utiliser, je trouve ça plutôt simple...
>
> 2008/9/1 Pierre Valade <pierre.val...@...>
>
>
>
>
>
> > Merci Michel. Donc effectivement aucune solution pour faire simplement
> > ce que je voulais :)
>
> > On 1 sep, 07:33, "Michel Belleville" <michel.bellevi...@...>
> > wrote:
> > > Tiens, au fait, qu'en dit la doc ?...
>
> > > Conditional layouts
>
> > > If you have a layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>that
> > > by default is applied to all the actions of a controller, you still
> > > have the option of rendering a given action or set of actions without a
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>,
> > > or restricting a
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>to
> > > only a single action or a set of actions. The
> > > :only and :except options can be passed to the
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>call.
> > > For example:
>
> > >   class WeblogController < ActionController::Base
> > >     layout "weblog_standard", :except => :rss
>
> > >     # ...
>
> > >   end
>
> > >  This will assign "weblog_standard" as the WeblogController's
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>except
> > > for the
> > > rss action, which will not wrap a
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>around
> > > the rendered view.
>
> > > Both the :only and :except condition can accept an arbitrary number of
> > > method references, so #:except => [ :rss, :text_only ] is valid, as is
> > :except
> > > => :rss.
> > > Using a different
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>in
> > > the action render call
>
> > > If most of your actions use the same
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>,
> > > it makes perfect sense to define a controller-wide
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>as
> > > described above. Sometimes you'll have exceptions where one action
> > > wants
> > > to use a different
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>than
> > > the rest of the controller. You can do this by passing a
> > > :layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>option
> > > to the
> > > render call. For example:
>
> > >   class WeblogController < ActionController::Base
> > >     layout "weblog_standard"
>
> > >     def help
> > >       render :action => "help", :layout => "help"
> > >     end
> > >   end
>
> > >  This will render the help action with the "help"
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho..
> > .>instead
> > > of the controller-wide "weblog_standard"
> > > layout<
> >http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho...>.
>
> > > --
> > > Michel Belleville
>
> --
> Michel Belleville
--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse railsfrance@...
Pour résilier votre abonnement envoyez un e-mail à l'adresse railsfrance-unsubscribe@...
-~----------~----~----~----~------~----~------~--~---


Gmane