# problems with methods... help

**URL:** <https://discuss.rubyonrails.org/t/problems-with-methods-help/30128>\
**Category:** rubyonrails-talk\
**Created:** [June 2, 2008, 11:27pm UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128 "2008-06-02T23:27:37Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_Rek2](https://avatars.discourse-cdn.com/v4/letter/_/e5b9ba/32.png) [@\_Rek2](https://discuss.rubyonrails.org/u/_Rek2)\
**Post date:** [June 2, 2008, 11:27pm UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/1 "2008-06-02T23:27:37Z")

</div>

Hi I made a simple example that is not the original but is giving me the same issue.. I create a method on my controller.. and make it so I cant sent him data to work with and return me the results.. but I keep getting that is an underfined method..! ;-(

error:

ActionView::TemplateError (undefined method `paco' for #\<#\<Class:0x2b1dcace86d8\>:0x2b1dcafabc80\>) on line #10 of app/views/rosteritems/\_amigos.rhtml: 7: 8: \<tr class="\<%= cycle('odd', 'even') -%\>"\> 9: \<% grupo.each do |amigo| %\> 10: \<td\>lolo \<%= paco(amigo.jid) %\>\</td\> 11: \<td\>\<%= amigo.jid %\>\</td\> 12: \<% end %\> 13: \</tr\>

the controller method paco:

&nbsp;&nbsp;def paco(msg)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

obviosly this is simple as it gets for the example.. I don't know why is saying that paco is undefined!

thanks.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 2, 2008, 11:50pm UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/2 "2008-06-02T23:50:31Z")

</div>

Controller methods are not available in views. Put the def paco method in the roster\_items\_helper.rb helper and it will be available in the view.

c.

rek2 wrote:

---

<div class="post-metadata">

**Author:** ![\_Rek2](https://avatars.discourse-cdn.com/v4/letter/_/e5b9ba/32.png) [@\_Rek2](https://discuss.rubyonrails.org/u/_Rek2)\
**Post date:** [June 3, 2008, 12:27am UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/3 "2008-06-03T00:27:26Z")

</div>

Cayce Balara wrote:

> Controller methods are not available in views. Put the def paco method in the roster\_items\_helper.rb helper and it will be available in the view.
> 
> c. &nbsp;&nbsp;

Hi Balara, I did that and still no luck.. I am with you but unfortunately is not working. ☹the only thing different I am doing is calling it from a \_file (a partial..)

any idea?

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [June 3, 2008, 12:41am UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/4 "2008-06-03T00:41:38Z")

</div>

> Cayce Balara wrote: \> Controller methods are not available in views. Put the def paco method \> in the roster\_items\_helper.rb helper and it will be available in the \> view.
> 
> \> c.
> 
> Hi Balara, I did that and still no luck.. I am with you but unfortunately is not working. ☹the only thing different I am doing is calling it from a \_file (a partial..)

What did you actually put in roster\_items\_helper.rb (this assumes that either the controller in question is the roster\_items one or you've got helper :all in application.rb)

Fred

---

<div class="post-metadata">

**Author:** ![\_Rek2](https://avatars.discourse-cdn.com/v4/letter/_/e5b9ba/32.png) [@\_Rek2](https://discuss.rubyonrails.org/u/_Rek2)\
**Post date:** [June 3, 2008, 12:56am UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/5 "2008-06-03T00:56:18Z")

</div>

Frederick Cheung wrote:

> > Cayce Balara wrote: &nbsp;&nbsp;&nbsp;&nbsp;
> > 
> > > Controller methods are not available in views. Put the def paco method in the roster\_items\_helper.rb helper and it will be available in the view. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> > 
> > Hi Balara, I did that and still no luck.. I am with you but unfortunately is not working. ☹the only thing different I am doing is calling it from a \_file (a partial..)
> 
> What did you actually put in roster\_items\_helper.rb (this assumes that either the controller in question is the roster\_items one or you've got helper :all in application.rb)

Hi Fred to keep it simple and test, I am doing someting simple from the view partial I am calling the methond like: paco(myvariable)

and in the method I got something like:

def paco(msg) &nbsp;&nbsp;&nbsp;end

this is just to see if it sees it.. but it says paco does not exists. and yes I did try the method to do something just in case rails need that but same result I even try to put it on the application helper file.

Thanks

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 3, 2008, 1:27am UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/6 "2008-06-03T01:27:19Z")

</div>

rek2 wrote:

> Frederick Cheung wrote:
> 
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> 
> Hi Fred to keep it simple and test, I am doing someting simple from the view partial I am calling the methond like: paco(myvariable)
> 
> and in the method I got something like:
> 
> def paco(msg) &nbsp;&nbsp;&nbsp;end
> 
> this is just to see if it sees it.. but it says paco does not exists. and yes I did try the method to do something just in case rails need that but same result I even try to put it on the application helper file.
> 
> Thanks

Okay, in case I've misunderstood your controller layout, put it in the Application Helper, application\_helper.rb. Absent other code, that file should look like this:

# Methods added to this helper will be available to all templates in the application. module ApplicationHelper &nbsp;&nbsp;def paco(msg) &nbsp;&nbsp;end end

If you do that you will be able to call \<%= paco(x) %\> from your view. Defining paco in your controller, it will never be available in your view.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 3, 2008, 1:30am UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/7 "2008-06-03T01:30:20Z")

</div>

rek2 wrote:

> Cayce Balara wrote:
> 
> > Controller methods are not available in views. Put the def paco method in the roster\_items\_helper.rb helper and it will be available in the view.
> > 
> > c. &nbsp;&nbsp;
> 
> Hi Balara, I did that and still no luck.. I am with you but unfortunately is not working. ☹the only thing different I am doing is calling it from a \_file (a partial..)
> 
> any idea?

Looking back at your original code, it should have been rosteritems\_helper.rb not roster\_items\_helper.rb - sorry about that. But putting it in application\_helper.rb like I suggested above should work just fine, also.

---

<div class="post-metadata">

**Author:** ![\_Rek2](https://avatars.discourse-cdn.com/v4/letter/_/e5b9ba/32.png) [@\_Rek2](https://discuss.rubyonrails.org/u/_Rek2)\
**Post date:** [June 3, 2008, 5:08pm UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/8 "2008-06-03T17:08:26Z")

</div>

Hi, sorry I missed this email, yes I notes you got the wrong name but is ok I understood. I did put it on application helper of course.. and still not working ☹is odd very odd and is driving me insane.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 3, 2008, 5:30pm UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/9 "2008-06-03T17:30:30Z")

</div>

rek2 wrote:

> Hi, sorry I missed this email, yes I notes you got the wrong name but is ok I understood. I did put it on application helper of course.. and still not working☹is odd very odd and is driving me insane.

That is very odd - any method defined in application\_helper.rb should be available in any view. Are you certain that you are still getting the same "undefined method `paco' for" error message?

Your next steps in debugging are to remove the paco call in your view and make sure that the view itself without it is working correctly in all other respects.

---

<div class="post-metadata">

**Author:** ![\_Rek2](https://avatars.discourse-cdn.com/v4/letter/_/e5b9ba/32.png) [@\_Rek2](https://discuss.rubyonrails.org/u/_Rek2)\
**Post date:** [June 3, 2008, 7:06pm UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/10 "2008-06-03T19:06:27Z")

</div>

Cayce Balara wrote:

> rek2 wrote: &nbsp;&nbsp;
> 
> > Hi, sorry I missed this email, yes I notes you got the wrong name but is ok I understood. I did put it on application helper of course.. and still not working ☹is odd very odd and is driving me insane. &nbsp;&nbsp;&nbsp;&nbsp; That is very odd - any method defined in application\_helper.rb should be available in any view. Are you certain that you are still getting the same "undefined method `paco' for" error message?
> 
> Your next steps in debugging are to remove the paco call in your view and make sure that the view itself without it is working correctly in all other respects. &nbsp;&nbsp;

yes I know.. I done this before but with out passing a variable to the method..

here is the method: # Methods added to this helper will be available to all templates in the application. module ApplicationHelper &nbsp;&nbsp;&nbsp;&nbsp;def paco(lo) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;example = lo &nbsp;&nbsp;&nbsp;&nbsp;end end

this is the error: actionView::TemplateError (undefined method `paco' for #\<#\<Class:0x2ad1f17d71f0\>:0x2ad1f17e5bb0\>) on line #9 of app/views/rosteritems/\_amigos.rhtml: 6: 7: \<tr class="\<%= cycle('odd', 'even') -%\>"\> 8: \<% grupo.each do |amigo| %\> 9: \<td\>\<%= paco(amigo.jid) %\>\</td\> 10: \<td\>\<%= amigo.jid %\>\</td\> 11: \<% end %\> 12: \</tr\>

see... this code where I add paco(amigo.jid) is been called by an ajax method. just in case.. here it is. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def jidamigos &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@authreg\_in = session[:authreg] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@name = Authreg.find\_by\_id(@authreg\_in) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name2 = (@name.username + "@" + @name.realm) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@amigos = Rosteritems.find( :all, :conditions =\> { :"collection-owner" =\> "#{name2}" }) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :partial =\> 'amigos' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

it calles the partial amigos so \_amigos is getting in.. all this works.. and it shows the list just right.. is only when I add to the view the call to the "paco" method to pass it the ID of the user so it can check and return if he is online or not and also put it on the view.

Thanks

---

<div class="post-metadata">

**Author:** ![Obie\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/o/ea666f/32.png) [@Obie\_Fernandez](https://discuss.rubyonrails.org/u/Obie_Fernandez)\
**Post date:** [June 3, 2008, 7:20pm UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/11 "2008-06-03T19:20:14Z")

</div>

Rek,

Try this

class MyController \< ApplicationController

&nbsp;&nbsp;helper\_method :paco

end

Look at the corresponding API documentation for helper\_method for more information. [http://api.rubyonrails.com/classes/ActionController/Helpers/ClassMethods.html#M000284](http://api.rubyonrails.com/classes/ActionController/Helpers/ClassMethods.html#M000284)

Cheers, Obie

---

<div class="post-metadata">

**Author:** ![\_Rek2](https://avatars.discourse-cdn.com/v4/letter/_/e5b9ba/32.png) [@\_Rek2](https://discuss.rubyonrails.org/u/_Rek2)\
**Post date:** [June 5, 2008, 1:07am UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/12 "2008-06-05T01:07:30Z")

</div>

Hi, thanks for all the help.. but \*Still\* can't get this to work.. I have done 1000 of methods, and all this is a big application and all the methods works.. the only difference is that this is the first time I have to pass it a variable and receive back a value.

I am going nuts, I have check books and online docs.. what I am doing is correct but is not working. the only thing different like I say before is that all this starts with a autoupdate ajax call, that calls a method and a partial the partial is the one that calls this method that does not work.. ☹is there a bug with this?

Obie Fernandez wrote:

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 5, 2008, 3:59am UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/13 "2008-06-05T03:59:57Z")

</div>

rek2 wrote:

> Hi, thanks for all the help.. but \*Still\* can't get this to work.. I have done 1000 of methods, and all this is a big application and all the methods works.. the only difference is that this is the first time I have to pass it a variable and receive back a value.
> 
> I am going nuts, I have check books and online docs.. what I am doing is correct but is not working. the only thing different like I say before is that all this starts with a autoupdate ajax call, that calls a method and a partial the partial is the one that calls this method that does not work.. ☹is there a bug with this?

Well, I'm stuck then. Based on everything you've posted and say you have done, it should have worked at least three times. I sure don't like giving up - I'm open to plugging your code into a test app and seeing what happens if you want to send it to me.

---

<div class="post-metadata">

**Author:** ![\_Rek2](https://avatars.discourse-cdn.com/v4/letter/_/e5b9ba/32.png) [@\_Rek2](https://discuss.rubyonrails.org/u/_Rek2)\
**Post date:** [June 5, 2008, 4:20am UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/14 "2008-06-05T04:20:25Z")

</div>

> Well, I'm stuck then. Based on everything you've posted and say you have done, it should have worked at least three times. I sure don't like giving up - I'm open to plugging your code into a test app and seeing what happens if you want to send it to me. &nbsp;&nbsp; Fire is over!!! hehe turns out it was mongrel and apache.. I just needed to "restart" this two.. it came to me after I though wait a second I am caching with apache.. :-/ it sucks that everytime I change the code I need to restart this two is there anyway to bypass this? I am sure others new to rails will have this problem sooner or late when adding something to a similar setup THANKS to everyone that help, we all were right.. 🙂

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 5, 2008, 4:26am UTC](https://discuss.rubyonrails.org/t/problems-with-methods-help/30128/15 "2008-06-05T04:26:44Z")

</div>

rek2 wrote:

> > Well, I'm stuck then. Based on everything you've posted and say you have done, it should have worked at least three times. I sure don't like giving up - I'm open to plugging your code into a test app and seeing what happens if you want to send it to me. &nbsp;&nbsp; Fire is over!!! hehe turns out it was mongrel and apache.. I just needed to "restart" this two.. it came to me after I though wait a second I am caching with apache.. :-/ it sucks that everytime I change the code I need to restart this two is there anyway to bypass this? I am sure others new to rails will have this problem sooner or late when adding something to a similar setup THANKS to everyone that help, we all were right.. 🙂

Kill me. Kill me now.

You could do your development using a local server that's suitably speedy and doesn't need to be restarted, like Webrick.
