# Calling method from view

**URL:** <https://www.ruby-forum.com/t/calling-method-from-view/142527>\
**Category:** Rails\
**Created:** [July 8, 2008, 9:57pm UTC](https://www.ruby-forum.com/t/calling-method-from-view/142527 "2008-07-08T21:57:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 8, 2008, 9:57pm UTC](https://www.ruby-forum.com/t/calling-method-from-view/142527/1 "2008-07-08T21:57:55Z")

</div>

I have this list of users that I capture in a method which is users that  
one individual is responciable for. In my view I iterate through that  
list of users to place the name of each user into a table.

I also have this hashPassword method that takes the username and a key  
and generates the appropriate single sign on hash for a user. My problem  
is that I am iterating through the users in the view and I need to call  
that hashPassword method from the view. I have tried saying:

\<% @hash = hassPassword(. . .) %\>

But rails doesn’t like that. Is there a way to call a method from the  
view? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 8, 2008, 10:17pm UTC](https://www.ruby-forum.com/t/calling-method-from-view/142527/2 "2008-07-08T22:17:46Z")

</div>

Sure, you can call methods from a view. Where is hashPassword defined?

Craig

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 8, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/calling-method-from-view/142527/3 "2008-07-08T22:33:54Z")

</div>

Craig D. wrote:

> Sure, you can call methods from a view. Where is hashPassword defined?
> 
> Craig

It’s define in my controller and I thought you could call it too, but I  
get this error:

undefined method `hashPassword’ for #\<#Class:0x4703e48:0x4703e20\>

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 8, 2008, 11:15pm UTC](https://www.ruby-forum.com/t/calling-method-from-view/142527/4 "2008-07-08T23:15:50Z")

</div>

I got it. I added the method to the application.rb file and all is good.
