I have a Rails 4 application. I have a search function with a select field. Now I'm getting this error:
NoMethodeError: undefined method 'map' for "5":String: select * from users inner join user_texts on users.id = user_id where text_id = ?
Here's view:
<% form_tag user_path do
<% select_tag :text_id, Option_from_collection_for_select(text.all, :id, :name, params[:text_id]), include_blank: true %>
<%= button_to '#', class: 'btn btn-default' do %>
<% t(:find) %>
<% end %>
Here's controller:
def index
if params[:text_id].present?
@users = User.search params[:text_id]
end
@users = User.all
end
Here's model:
def self.search(text_id)
find_by_sql("select * from users inner join user_texts on users.id = user_id where text_id = ?
", text_id)
end
When I do this, it works perfect:
select * from users inner join user_texts on users.id = user_id where text_id = 5