problems with methods... help

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:

  def paco(msg)

         end

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

thanks.

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:

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. :frowning: the only thing different I am doing is calling it from a _file (a partial..)

any idea?

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. :frowning: 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

Frederick Cheung 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.       

Hi Balara, I did that and still no luck.. I am with you but unfortunately is not working. :frowning: 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)    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

rek2 wrote:

Frederick Cheung wrote:

      

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)    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   def paco(msg)   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.

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.   

Hi Balara, I did that and still no luck.. I am with you but unfortunately is not working. :frowning: 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.

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 :frowning: is odd very odd and is driving me insane.

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 :frowning: 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.

Cayce Balara wrote:

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 :frowning: 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.   

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     def paco(lo)         example = lo     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.          def jidamigos                 @authreg_in = session[:authreg]                 @name = Authreg.find_by_id(@authreg_in)                 name2 = (@name.username + "@" + @name.realm)                 @amigos = Rosteritems.find( :all, :conditions => { :"collection-owner" => "#{name2}" })                  render :partial => 'amigos'         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

Rek,

Try this

class MyController < ApplicationController

  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

Cheers, Obie

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.. :frowning: is there a bug with this?

Obie Fernandez wrote:

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.. :frowning: 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.

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.    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.. :slight_smile:

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.    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.. :slight_smile:

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.