¿Cómo recuperar el valor de la página actual en un controlador?

I am using Ruby on Rails v3.0.9 and I would to use a method that works as-like the current_page?(options) method (included in the RoR ActionView::Helpers::UrlHelper Class), , pero in my controllers. That is, I would like to check en mis controladores (not in view files) if the current "browsed" page corresponds to a RoR path (eg: signup_path, signin_path, etc ...).

Is it possible? If so, how can I accomplish that?

preguntado el 28 de agosto de 11 a las 03:08

Why? What's the purpose of this code? -

Tried to include this helper in your controller? include ActionView::Helpers::UrlHelper -

But, by definition, whatever action you're in is the current page. What are you trying to accomplish with this code? -

@jdl, code re-use means you often have code in methods other than the action itself, used my multiple actions/controllers. If you were hard-coding this code into some action, then yes, you'd already know, but obviously that's not the case. -

The page is the view action. As everyone else asks - what are you trying to do? If you explain that better people can suggest a good answer. Talking about views info in the controller this way doesn't make sense without more context. -

2 Respuestas

My advice to you: if you are in need of this method in controller, than either you have ugly routes, or you have ugly code in your controller.

Better think what you can improve in your existing code to avoid using "current_page?" in controller.

Respondido 28 ago 11, 17:08

Something is fundamentally wrong with an action that doesn't know what the current page is, but until we see some real code I don't think we're going to get to the bottom of that.

This Railscast should give you some ideas on building the wizard that you're after.


Respondido 28 ago 11, 18:08

I followed exactly that railscast inserting (as partial template) the first step form in my homepage. What I would like to make is to redirect next steps (second step and so on) to the page related to the controller action that normally handles those steps. - Backo

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.