0

I have a controller action

  def create
    @subject_decision = SubjectDecision.new(subject_decision_params)

    respond_to do |format|
      if @subject_decision.save
        format.html { redirect_to @subject_decision, notice: 'Subject decision was successfully created.' }
        format.json { render :show, status: :created, location: @subject_decision }
      else
        format.html { render :new }
        format.json { render json: @subject_decision.errors, status: :unprocessable_entity }
      end
    end
  end

with a private method:

def subject_decision_params
  params.require(:subject_decision).permit(:decision_block_id, :choice_value, :timeline_id, :practice)
end

and a button_to in a view like:

<%= button_to "Choice A", timeline_subject_decisions_path(timeline_id: @timeline.id), method: :post, params:
    { subject_decision:
        {
            decision_block_id: @db.id,
            choice_value: 'a',
            timeline_id: @timeline.id,
            practice: true,
        }
    } 
%>

But when I click the button I get the following rails error:

undefined method `permit' for "choice_value=a&decision_block_id=&practice=true&timeline_id=1":String

Any clues on why I can not submit the form(button_to) like this?

Shawnzam
  • 327
  • 2
  • 11
  • 1
    This seems to indicate that nested hashes doesn't work yet... but you can fake it up with eg `'subject_decision[decision_block_id]' => @db.id` etc - even if it's a bit ugly https://groups.google.com/forum/#!topic/rubyonrails-core/otqJ-ClTyFk – Taryn East Oct 05 '16 at 21:37
  • 1
    @TarynEast this worked! Thanks. – Shawnzam Oct 05 '16 at 23:46

1 Answers1

2

You can format your button_to as

<%= button_to "Choice A", timeline_subject_decisions_path(timeline_id: @timeline.id), method: :post, params:
    {   
        'subject_decision[decision_block_id]' => @db.id,
        'subject_decision[choice_value]' => 'a',
        'subject_decision[timeline_id]' => @timeline.id,
        'subject_decision[practice]' => true,
    }
%>
Shawnzam
  • 327
  • 2
  • 11