Forum: Ruby on Rails If... what?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A68e38809ace8356ec2fa6aa1d13246b?d=identicon&s=25 Vince W. (vince)
on 2006-06-13 20:11
I have a simple div in my layout that I would like to change depending
on the action.  For instance in the account/signup I would like it to
use <div id="register"> but in account/login I would like it to use <div
id="login">

I'm trying to find the right if statement to use here.. I thought that
maybe:

if :action => login would work but it doesn't..

thanks..
Chris Bruce (Guest)
on 2006-06-13 20:17
(Received via mailing list)
Try  controller.action_name or controller.controller_name
Alex Wayne (Guest)
on 2006-06-13 21:09
Vince W. wrote:
> I have a simple div in my layout that I would like to change depending
> on the action.  For instance in the account/signup I would like it to
> use <div id="register"> but in account/login I would like it to use <div
> id="login">
>
> I'm trying to find the right if statement to use here.. I thought that
> maybe:
>
> if :action => login would work but it doesn't..
>
> thanks..

<div id="<%= params[:action] %>">

or, from a helper:

  def sidebar_id(action)
    action = action.to_s
    case action
      when 'signup' : 'register'
      when 'foo'    : 'bar'
      else          : action
    end
  end

  # View
  <div id="<%= sidebar_id(params[:action]) %>">
This topic is locked and can not be replied to.