Results 1 to 3 of 3

Thread: Help deciphering Ruby error

  1. #1
    Join Date
    May 2006
    Posts
    7

    Default Help deciphering Ruby error

    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:

    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:

    Code:
    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:

    Code:
    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:

    Code:
    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!

  2. #2
    Join Date
    Mar 2006
    Location
    Tulsa
    Posts
    121

    Default

    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.
    leave my elevator... alone.

    between something and nothing

  3. #3
    Join Date
    May 2006
    Posts
    7

    Default

    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:

    Code:
    @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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •