mayorsanmayor
mayorsanmayor

Reputation: 2988

ArgumentError - bad value for range

Looks like the Range method has been enhanced in Ruby, I'm using v2.5.1 and it's not working as expected. This was working before, but now is not working.

I have this line of code:

@events = Event.where(start: params[:start]..params[:ends])

And the start and ends symbols are expecting a date value. Here's the log in my rails console.

Started GET "/events.json?start=2018-05-27&end=2018-07-08&_=1529068714340" for 127.0.0.1 at 2018-06-15 16:18:34 +0300
Processing by EventsController#index as JSON
  Parameters: {"start"=>"2018-05-27", "end"=>"2018-07-08", "_"=>"1529068714340"}

But I'm getting this error in the console -

ArgumentError - bad value for range:
  app/controllers/events_controller.rb:7:in `index'

Please, how can I get the proper range?

Here's the repo incase you want to check it out - https://github.com/mayordwells/fullcalendar-rails-demo

Upvotes: 1

Views: 1450

Answers (2)

David Aldridge
David Aldridge

Reputation: 52346

You are looking for a parameter with params[:ends] but your parameter is "end"=>"2018-07-08".

ends vs end

Upvotes: 2

andriy-baran
andriy-baran

Reputation: 739

You need to transform string parameters into Date objects

Date.parse(params[:start])..Date.parse(params[:ends])

Upvotes: 0

Related Questions