Is there anyway to get method name in view?

I have tried to search in google with keyword “rails get method name in
view”
but i couldn’t find any answer

In this case i want to get method name in view for example

http://localhost:3000/todo/all_project_todos/14

  • method name is “all_project_todos”

http://localhost:3000/todo/completed_todos/14

  • method name is “completed_todos”

Is there any way i can do this ?

Thank you
Golf

Sijo Kg wrote:

action name

params[:action]

similarly controler name params[:controller]

Sijo

Thank you Sijo

action name

params[:action]

similarly controler name params[:controller]

Sijo

Thriving K. wrote:

In this case i want to get method name in view for example

http://localhost:3000/todo/all_project_todos/14

  • method name is “all_project_todos”

http://localhost:3000/todo/completed_todos/14

  • method name is “completed_todos”

I can’t put my finger on it right now, but this approach feels wrong to
me. Maybe it has something to do with my embrace of RESTful style
applications, but those URLs look redundant to me. The are both
referencing a “Todo” resource identified by 14. It shouldn’t matter
whether it’s completed or not in this context.

As for the “all” and “completed” collection of “todos,” that could be
handled using named_scope. It just feels to me that the decision of what
to included in the collection is happing in the wrong place.

I would foresee URLs that look more like this:

Todo #14:
GET: http://example.com/todos/14

All project todos:
GET: http://example.com/projects/1/todos

Completed project todos:
GET: http://example.com/projects/1/todos?completed=true

All completed todos:
GET: http://example.com/todos?completed=true

This approach eliminates the need you’re requesting. And, this is also
likely why you were having trouble finding answers to your question
through Google. All I’m saying is to take that as a sign that maybe
you’re attempting something unconventional and there might be a better
approach.

Take this reply as a nudge to think about your design and don’t take it
as criticism, which it certainly is not intended to be.

References:
http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=M002227&name=named_scope
http://guides.rubyonrails.org/getting_started.html#rest

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs