Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6912681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:07:21+00:00 2026-05-27T09:07:21+00:00

When I run my application I am getting the following error: ArgumentError in StatesController#filter

  • 0

When I run my application I am getting the following error:

ArgumentError in StatesController#filter

wrong number of arguments (0 for 1)

My controller looks like this:

class StatesController < ApplicationController
    def filter(my_string)

        @new_array = []
        @new_array = state.each {|x| if /#my_string/i =~ x then puts x end}
        return @new_array

    end

end

And my view looks like this:

 <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>States</title>
  </head>

  <body>

        <% States.filter(params[:substring]) %>
        <p><%= @new_array.each %></p>
        <% if @new_array.size = 0 %>
        <p>No matches!</p>

    </body>

</html>

What wrong with my code?

thanks so much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:07:22+00:00Added an answer on May 27, 2026 at 9:07 am

    The filter method you have in the StatesController is an action. Such actions do not accept parameters. A better way to achieve what you are trying to do would be to create a model called State like so. And add the filter method to it:

    # app/models/state.rb
    class State
      def filter(params[:my_string])
        @new_array = []
        @new_array = state.each {|x| if /#my_string/i =~ x then puts x end}
        return @new_array
      end
    end
    

    In your controller, you should now have something like the following:

    class StatesController < ApplicationController
      def filter
        @states = State.filter(params[:sub_string])
      end
    end
    

    Then in the corresponding view:

    <% if @states.empty? %>
      <p>No matches!</p>
    <% else %>
      <p>
        <% @states.each do |state| %>
          <%= state %>
        <% end %>
      </p>
    <% end %>
    

    What this does is uses the model to load an array into an instance variable. This instance variable (started with the @) is accessible in the view that is rendered in the controller action. The action we are using is specified as filter.

    In the view, I check if there are any results in the array by using the empty? method. Otherwise i just loop through the array.

    Now, this will only work provided you have the params[:sub_string] in the headers. So you will need to make sure you have something like ?sub_string=mystring in the url.

    Given your question, and your code layout, I would assume you are fairly new to rails. I really recommend having a good read through the getting started guide here: http://guides.rubyonrails.org/getting_started.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the following exception when I run my application in Release mode from
This is the exception that I am getting when I run my application with
I'm getting in trouble. I'm trying to emulate the call Application.Run using Application.DoEvents... this
I am getting the following error message when compiling or attempting to run my
I'm getting the following error when attempting to move an application from a state
when running my osgi application i am getting following error: !ENTRY com.mypackage.commons 4 0
I'm getting the following error when trying to run a JSP. I'm using Tomcat
I am getting the following error when i tried to run my Java REST
i am experiencing following error while trying to run application on heroku 2011-06-03T11:24:25-07:00 heroku[nginx]:
hi my application contains SQLite .My application some time getting the following error java.lang.RuntimeException:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.