I am pretty new to rails and currently coding my first application. I created a search to search through my Users (either usernames or tags - using acts_as_taggable_on gem). Following error appears:
ArgumentError in UsersController#index
wrong number of arguments (0 for 1)
User Model
# Search
def self.search(search)
if search
where(["username LIKE ?", "%#{search}%"])
elsif searchtags
none
else
all
end
end
# Search Tags
def self.searchtags(searchtags)
if searchtags
tagged_with(["#{searchtags}"], :any => true, :wild => true)
else
none
end
end
User Controller
def index
@users = User.search(params[:search])
@tagged_users = User.searchtags(params[:searchtags])
end
User Index View
= form_tag users_path, :method => 'get' do
= text_field_tag :search, params[:search]
= submit_tag "Search"
= form_tag users_path, :method => 'get' do
= text_field_tag :searchtags, params[:searchtags]
= submit_tag "Search Tags"
- @users.each do |user|
= image_tag gravatar_for user if user.use_gravatar == true
= image_tag user.avatar_filename.url if user.use_gravatar == false
%h2= link_to user.username, user
%p= link_to "Favorite", userfavorite_user_path(user, type: "favorite"), method: :get
%p= link_to "Unfavorite", userfavorite_user_path(user, type: "unfavorite"), method: :get
%p= user.tag_list
- @tagged_users.each do |user|
= image_tag gravatar_for user if user.use_gravatar == true
= image_tag user.avatar_filename.url if user.use_gravatar == false
%h2= link_to user.username, user
%p= link_to "Favorite", userfavorite_user_path(user, type: "favorite"), method: :get
%p= link_to "Unfavorite", userfavorite_user_path(user, type: "unfavorite"), method: :get
%p= user.tag_list
IMPORTANT!
The error only appears with this piece of code:
elsif searchtags
none
in the User Model, without it everything works fine. I need it though to prevent duplications.
Thanks in advance for your help!