PDA

View Full Version : Help deciphering Ruby error



AegisSailor
05-07-2006, 12:57 AM
Greetings, all-knowing-ones,

I've been hacking at this error for hours now and I've run out of ideas. Using the component feature, I'm trying to pass two parameters from a view, through a helper, to the target controller, which then in turn passes the parameter to the model for incorporation into a DB query. I keep getting the error:


ArgumentError in Link managerController#show
wrong number of arguments (2 for 1)

I don't understand what is happening here, I'm passing two parameters and I'm using two parameters. Let me walk you through the relevant parts of my code:



<div id="wrapper">
<% if flash[:notice] -%>
<div id="notice"><%= flash[:notice] %></div>
<% end -%>

<%= insert_context_menu%>

<%= @content_for_layout %>
</div>

the call to insert_context_menu is to a helper that looks like this:



def insert_context_menu
if @show_context
render_component(:controller => 'LinkManager',
:action => 'show',
:params =>{"cat" => "admin","sub" =>"user_manager"},
:layout => nil)
end
end


So, I've assigned values to two parameters, cat and sub. The helper calls on the following action:



def show
@local_links = Link.get_links (params[:cat,:sub])
end


I'm now calling on the model to query the database and return data I need to build context-sensitive hyper-links. I think I'm correctly passing the two parameters that orginated in the helper. Here's the method in the model:



def self.get_links
link.find(:first,
:conditions => ["category = ? AND sub_category = ?", cat,sub])
end


This query works fine when I tested by creating and setting two variables locally. But as soon as this whole thing runs, I get the wrong number of arguments error.

Any help in restoring my sanity would be much appreciated!

Thanks!

grant
05-07-2006, 10:27 AM
Well, I don't know much about RUBY, but down at the bottom it looks as if you're trying to call your links twice instead of the catagories on the bottom one. Unless that's how RUBY works. I use Wordpress and if you try using 2 different link functions it throws things way out of whack.

Not sure if any of this helps though. Just thought I'd throw that out.

AegisSailor
05-07-2006, 12:01 PM
Thanks for the input, but I've just found a work around to the problem. I'd still like to know why the original version didn't work though with passed parameters, but would work with local variables. I need the closure, so if anybody can unravel the mystery, I'd appreciate it.

Anyway, my work-around is to call the query from the controller, which was recieving parameters just fine. Instead of calling on a method in the model to execute the query, I just added this line to the controller method:



@local_links = Link.find_all_by_category_and_sub_category(params[:cat],params[:sub])


This is working just fine, and ends up as cleaner code anyway.

Thanks,

Roger