All threads / Recurring Select Accepts "Null" As a Valid Rule
Ask A Question

Notifications

You’re not receiving notifications from this thread.

Recurring Select Accepts "Null" As a Valid Rule

Steve Polito asked in Gems / Libraries

I followed the Chris' excellent tutorial on Recurring events with the ice_cube gem. However, I was running into an issue when the value of recurring was set to - not recurring -. If I went to create or update an event, I would get the following error:

undefined method 'to_hash' for nil:NilClass, which pointed to this line super(RecurringSelect.dirty_hash_to_rule(value).to_hash)

The actual value of this field is null, and for some reason this value was being accepted as a RecurringSelect.is_valid_rule?.

I ended up rewriting my recurring= method to the following to solve the issue.

  def recurring=(value)
    if value == "null"
      super(nil)
    elsif RecurringSelect.is_valid_rule?(value)
      super(RecurringSelect.dirty_hash_to_rule(value).to_hash)
    else
      super(nil)
    end
  end
  1. Is my solution acceptable?
  2. Any reason why I'm running into this issue? Is it because I'm running a different version of Rails? I'm on rails 5
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 61,501+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.