index.html.erb:
<%= form_tag(sheets_path, :method => "get", id: "search-form") do %>
<%= date_field :search, params[:search], placeholder: "Procurar sheets" %>
<%= submit_tag "Procurar", :name => nil,class: "button" %>
<% end %>
sheets_controller.rb:
def index
@sheets = Sheet.where(user_id: current_user)
if params[:search]
@sheets = Sheet.search(params[:search], current_user.id)
else
@sheets = Sheet.where(user_id: current_user)
end
end
sheet.rb:
def self.search(search, userid)
date_start = search
date_end = '2017-07-27T00:00:00'#hardcoded, for now, implement date_start +24h later
self.where("user_id =" + userid.to_s ).where("inicio > ?", date_start).where("inicio < ?", date_end)
end
I make a first query let's say: 2017-07-03
it gives me the sheets where start_date is > than 2017-07-03 and displays it all ok, now let's say I query 2017-07-05
after, it gives me
- TypeError in SheetsController#index can't quote Array
and the link: http://localhost:3000/sheets?utf8=%E2%9C%93&search%5B%5B%222017-07-03%22%5D%5D=2017-07-05
and console:
Processing by SheetsController#index as HTML
Parameters: {"utf8"=>"✓", "search"=>{"\"2017-07-03\""=>"2017-07-05"}}
User Load (1.0ms) EXEC sp_executesql N'SELECT [users].* FROM [users] WHERE [users].[id] = @0 ORDER BY [users].[id] ASC OFFSET 0 ROWS FETCH NEXT @1 ROWS ONLY', N'@0 int, @1 int', @0 = 7, @1 = 1 [["id", nil], ["LIMIT", nil]]
Completed 500 Internal Server Error in 6ms (ActiveRecord: 1.0ms)
TypeError (can't quote Array):
app/models/sheet.rb:7:in `search'
How can I fix this? what is wrong with this?