# Adding a view (newby question)

**URL:** <https://www.ruby-forum.com/t/adding-a-view-newby-question/172372>\
**Category:** Rails\
**Created:** [July 20, 2009, 4:11pm UTC](https://www.ruby-forum.com/t/adding-a-view-newby-question/172372 "2009-07-20T16:11:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [July 20, 2009, 4:11pm UTC](https://www.ruby-forum.com/t/adding-a-view-newby-question/172372/1 "2009-07-20T16:11:15Z")

</div>

How do you add an extra view?  
I have “new, edit, show, etc.”.  
I’m having trouble using RESTful paths.  
“new\_viewname\_path” works for linking to the “new” view but if I try  
something like “myview\_viewname\_path” I get an error: “undefined local  
variable or method `myview\_viewname\_path’”  
Can anybody help?

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [July 20, 2009, 4:53pm UTC](https://www.ruby-forum.com/t/adding-a-view-newby-question/172372/2 "2009-07-20T16:53:08Z")

</div>

Jason Cheung wrote:

> How do you add an extra view?  
> I have “new, edit, show, etc.”.  
> I’m having trouble using RESTful paths.  
> “new\_viewname\_path” works for linking to the “new” view but if I try  
> something like “myview\_viewname\_path” I get an error: “undefined local  
> variable or method `myview\_viewname\_path’”  
> Can anybody help?

the ‘new’ path and the ‘edit’ path are the only ones that actually have  
the name of the action in them. The rest are determined based on  
whether you refer to the singular or plural version of the resource (eg  
comments vs comment) and the type of the request. I found this  
cheatsheet very handy when i started using REST:

> **[REST-cheatsheet.pdf](https://topfunky.com/clients/peepcode/REST-cheatsheet.pdf)**
>
> 78.73 KB

The cheatsheet shows you how to add custom actions as well: basically  
you put the action in your controller and moddify the entry for that  
resource in your routes.rb. The views themselves are not the problem  
you were encountering: if the action is run successfully it will drop  
through to the view automatically. To put it another way, a path points  
to a particular action in a particular controller, rather than to a  
view.

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [July 20, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/adding-a-view-newby-question/172372/3 "2009-07-20T17:22:15Z")

</div>

Max W. wrote:

> the ‘new’ path and the ‘edit’ path are the only ones that actually have  
> the name of the action in them. The rest are determined based on  
> whether you refer to the singular or plural version of the resource (eg  
> comments vs comment) and the type of the request. I found this  
> cheatsheet very handy when i started using REST:  
> [http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf](http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf)
> 
> The cheatsheet shows you how to add custom actions as well: basically  
> you put the action in your controller and moddify the entry for that  
> resource in your routes.rb. The views themselves are not the problem  
> you were encountering: if the action is run successfully it will drop  
> through to the view automatically. To put it another way, a path points  
> to a particular action in a particular controller, rather than to a  
> view.

Thanks a million max. That cheat sheet was great. I got it linking to  
the right view.  
I used “theview\_plural\_path(idNum)”.

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [July 20, 2009, 5:33pm UTC](https://www.ruby-forum.com/t/adding-a-view-newby-question/172372/4 "2009-07-20T17:33:47Z")

</div>

Jason Cheung wrote:

> Max W. wrote:
> 
> > the ‘new’ path and the ‘edit’ path are the only ones that actually have  
> > the name of the action in them. The rest are determined based on  
> > whether you refer to the singular or plural version of the resource (eg  
> > comments vs comment) and the type of the request. I found this  
> > cheatsheet very handy when i started using REST:  
> > [http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf](http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf)
> > 
> > The cheatsheet shows you how to add custom actions as well: basically  
> > you put the action in your controller and moddify the entry for that  
> > resource in your routes.rb. The views themselves are not the problem  
> > you were encountering: if the action is run successfully it will drop  
> > through to the view automatically. To put it another way, a path points  
> > to a particular action in a particular controller, rather than to a  
> > view.
> 
> Thanks a million max. That cheat sheet was great. I got it linking to  
> the right view.  
> I used “theview\_plural\_path(idNum)”.

BTW the reason that you can pass an object to the path, rather than it’s  
id, is that the method ‘to\_param’ will be called on the object, and by  
default this returns the id. So, it’s best to always pass the object to  
the path: later on, if you want the url to show the name, for example,  
rather than the id, you just override to\_param for that model and it  
magically works. If you’re always passing ids through then you would  
have to hunt out all the times you call that path and change them.
