# Is there anyway to get method name in view?

**URL:** <https://www.ruby-forum.com/t/is-there-anyway-to-get-method-name-in-view/172414>\
**Category:** Rails\
**Created:** [July 21, 2009, 6:44am UTC](https://www.ruby-forum.com/t/is-there-anyway-to-get-method-name-in-view/172414 "2009-07-21T06:44:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thriving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@thriving](https://www.ruby-forum.com/u/thriving)\
**Post date:** [July 21, 2009, 6:44am UTC](https://www.ruby-forum.com/t/is-there-anyway-to-get-method-name-in-view/172414/1 "2009-07-21T06:44:56Z")

</div>

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](http://localhost:3000/todo/all_project_todos/14)

- method name is “all\_project\_todos”

[http://localhost:3000/todo/completed\_todos/14](http://localhost:3000/todo/completed_todos/14)

- method name is “completed\_todos”

Is there any way i can do this ?

Thank you  
Golf

---

<div class="post-metadata">

**Author:** ![thriving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@thriving](https://www.ruby-forum.com/u/thriving)\
**Post date:** [July 21, 2009, 7:11am UTC](https://www.ruby-forum.com/t/is-there-anyway-to-get-method-name-in-view/172414/2 "2009-07-21T07:11:56Z")

</div>

Sijo Kg wrote:

> action name
> 
> params[:action]
> 
> similarly controler name params[:controller]
> 
> Sijo

Thank you Sijo

---

<div class="post-metadata">

**Author:** ![thriving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@thriving](https://www.ruby-forum.com/u/thriving)\
**Post date:** [July 21, 2009, 7:02am UTC](https://www.ruby-forum.com/t/is-there-anyway-to-get-method-name-in-view/172414/3 "2009-07-21T07:02:27Z")

</div>

action name

params[:action]

similarly controler name params[:controller]

Sijo

---

<div class="post-metadata">

**Author:** ![thriving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@thriving](https://www.ruby-forum.com/u/thriving)\
**Post date:** [July 21, 2009, 3:54pm UTC](https://www.ruby-forum.com/t/is-there-anyway-to-get-method-name-in-view/172414/4 "2009-07-21T15:54:11Z")

</div>

Thriving K. wrote:

> In this case i want to get method name in view for example
> 
> [http://localhost:3000/todo/all\_project\_todos/14](http://localhost:3000/todo/all_project_todos/14)
> 
> - method name is “all\_project\_todos”
> 
> [http://localhost:3000/todo/completed\_todos/14](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](http://example.com/todos/14)

All project todos:  
GET: [http://example.com/projects/1/todos](http://example.com/projects/1/todos)

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

All completed todos:  
GET: [http://example.com/todos?completed=true](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://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=M002227&name=named_scope)

> **[Getting Started with Rails — Ruby on Rails Guides](https://guides.rubyonrails.org/getting_started.html#rest)**
>
> Getting Started with RailsThis guide covers getting up and running with Ruby on Rails.After reading this guide, you will know: How to install Rails, create a new Rails application, and connect your application to a database. The general layout of a...
