title: ERROR: array value must start with "{"
body: <p>Works in development, but not production. When I submit a habit. All the days are checked:</p>
  
  <p><a href="https://i.stack.imgur.com/aplWI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aplWI.png" alt="enter image description here"></a></p>
  
  <p>And when I submit in heroku logs show:</p>
  
  <pre><code>2015-08-15T03:37:10.067022+00:00 app[web.1]: Processing by HabitsController#create as HTML
  2015-08-15T03:37:10.067084+00:00 app[web.1]:   Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"n+tS6pcb6WUHTCdV9BZqp/nFefhbPKAE+UTUouu2x1qK0pNulK+XNT4z8AhDuwEfZ1Z860fqnqQ/YXlARyplbQ==", "habit"=&gt;{"committed"=&gt;["sun", "mon", "tue", "wed", "thu", "fri", "sat", ""], "date_started(2i)"=&gt;"8", "date_started(3i)"=&gt;"14", "date_started(1i)"=&gt;"2015", "trigger"=&gt;"", "action"=&gt;"test", "target"=&gt;"", "reward"=&gt;"", "tag_list"=&gt;"", "conceal"=&gt;"0"}, "button"=&gt;""}
  </code></pre>
  
  <p>But then I get a validation error flash message because <code>:committed</code> days presence isn't coming out true even though they are all checked.</p>
  
  <p>With further investigation I realize that I can't <code>mark_completed</code> any of the habits in production, which I think is related to the above problem:</p>
  
  <pre><code>2015-08-15T03:34:24.227822+00:00 heroku[router]: at=info method=POST path="/habits/sort" host=www.personalcontrolcenter.com request_id=ef56c920-dee8-4797-967b-34354ff83fbc fwd="75.90.62.187" dyno=web.1 connect=0ms service=197ms status=500 bytes=274
  2015-08-15T03:34:29.713874+00:00 app[web.1]: Started PUT "/mark_completed/7" for 75.90.62.187 at 2015-08-14 23:34:29 -0400
  2015-08-15T03:34:29.720020+00:00 app[web.1]: Processing by HabitsController#mark_completed as JS
  2015-08-15T03:34:29.720027+00:00 app[web.1]:   Parameters: {"id"=&gt;"7"}
  2015-08-15T03:34:29.924799+00:00 app[web.1]: PG::InvalidTextRepresentation: ERROR:  array value must start with "{" or dimension information
  2015-08-15T03:34:29.924804+00:00 app[web.1]: : UPDATE "habits" SET "committed" = $1, "completed_at" = $2, "updated_at" = $3 WHERE "habits"."id" = $4
  2015-08-15T03:34:29.924807+00:00 app[web.1]: Completed 500 Internal Server Error in 204ms
  2015-08-15T03:34:29.926694+00:00 app[web.1]:
  2015-08-15T03:34:29.926697+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::InvalidTextRepresentation: ERROR:  array value must start with "{" or dimension information
  2015-08-15T03:34:29.926698+00:00 app[web.1]: : UPDATE "habits" SET "committed" = $1, "completed_at" = $2, "updated_at" = $3 WHERE "habits"."id" = $4):
  2015-08-15T03:34:29.926700+00:00 app[web.1]:   app/controllers/habits_controller.rb:32:in `mark_completed'
  </code></pre>
  
  <p>So I think we just need to rewrite the <code>habit_params</code> where I have <code>:committed =&gt; []</code>. I tried this without the brackets too.</p>
  
  <p><strong>habits_controller.rb</strong></p>
  
  <pre><code>  def create
      if current_user == nil
        # If there is no user, store the goal values to the session.
        session[:habit_date_started] = [params["habit"]["date_started(3i)"], params["habit"]["date_started(2i)"], params["habit"]["date_started(1i)"]].join('/')
        session[:habit_committed] = params["habit"]["committed"].reject(&amp;:empty?)
        session[:habit_action] = habit_params[:action]
        session[:habit_target] = habit_params[:target]
        session[:habit_reward] = habit_params[:reward]
        session[:habit_order] = habit_params[:order]
        session[:habit_missed_days] = habit_params[:missed_days]
        redirect_to valuation_signup_url
      else
        @habit = current_user.habits.build(habit_params)
        if @habit.conceal == true
          @habit.save_with_current_level
          redirect_to @habit, notice: 'Habit was secretly created. Remember, 3 strikes and your level restarts. Good luck!'
        elsif
          @habit.save_with_current_level
          track_activity @habit
          redirect_to @habit, notice: 'Habit was successfully created. Remember, 3 strikes and your level restarts. Good luck!'
        else
          flash.now[:danger] = 'Required Fields: "Committed to", "Started", and "Enter Habit"'
          render 'new'
        end
      end
    end
  
    def habit_params
      params.require(:habit).permit(
        :committed =&gt; [], # In development if I comment this line out it still passes
    end
  end
  </code></pre>
  
  <p><strong>habit.rb</strong></p>
  
  <pre><code>validates :committed, presence: true
  serialize :committed, Array
  
  def save_with_current_level
      self.levels.build
      self.levels.build
      self.levels.build
      self.levels.build
      self.levels.build
      self.save
  end
  </code></pre>
  
  <p><strong>development db</strong></p>
  
  <pre><code>t.text     "committed",    default: "---\n- sun\n- mon\n- tue\n- wed\n- thu\n- fri\n- sat\n"
  </code></pre>
  
  <p><strong>production db</strong></p>
  
  <pre><code>committed    | text[]                      | default '{sun,mon,tue,wed,thu,fri,sat}'::text[]
  </code></pre>
  
  <p><strong>_form</strong></p>
  
  <pre><code>&lt;%= f.collection_check_boxes :committed, Date::ABBR_DAYNAMES, :downcase, :to_s %&gt;
  </code></pre>