Easy way to convert URL back to route name?

Hi Dave,

There's probably a better way to do this, but I'm new
to rails so any help appreciated.

I'm not sure if this is what you're looking for, but views get
'knowledge' of their 'source' via controller.controller name and
controller.action_name.

So you can do:

if controller.controller_name == 'foo'
  # ... show something specific to foo
elsif controller.controller_name == 'bar'
  # ... show something specific to bar
end

If you want to make the code specific to both controller and action you
can do:

if controller.controller_name == 'foo' && controller.action_name ==
'show'

HTH,
Bill

bill walton wrote:

I'm not sure if this is what you're looking for, but views get
'knowledge' of their 'source' via controller.controller name and
controller.action_name.

Thanks Bill! I actually knew about that and wrote a similar capability
for some ASP work I do at work in my day job. Argh. Can't believe I
didn't think of that this time. Goes to show what happens when most of
your hobby coding is between 10pm and 1am...

Thanks again, worked perfectly!

-dave

Hi Dave,

bill walton wrote:
> I'm not sure if this is what you're looking for, but views get
> 'knowledge' of their 'source' via controller.controller name and
> controller.action_name.

Thanks Bill! I actually knew about that and wrote a similar capability
for some ASP work I do at work in my day job. Argh. Can't believe I
didn't think of that this time. Goes to show what happens when most of
your hobby coding is between 10pm and 1am...

:wink: Yep!

Thanks again, worked perfectly!

You're welcome. Glad it helped.

Best regards,
Bill