I have a model of goals with a number of attributes.
Once a goal is complete, it's marked as complete on a button press and then redirected to a new form which can add additional attributes to the goal model.
To me it made sense to store them on the goal model, as they are only ever linked to the goal, however, I can't get it to work correctly as I always get param is missing or the value is empty: goal.
Goal params are used as the standard CRUD params.
The goal_review_params are used once the goal is complete.
Is this possible to do outside of the 'update' action?
Controller:
class GoalsController < ApplicationController
before_action :authenticate_user!, except: [:index, :show, :completedgoals]
before_action :set_goal, only: [:show, :edit, :update, :destroy, :mark_completed, :goal_completed ]
def goal_completed
@authorize
if @goal.update(goal_review_params)
format.html { redirect_to @goal, notice: 'Goal review was successfully updated.' }
format.json { render :show, status: :ok, location: @goal }
else
format.html { redirect_to goal_completed_goal_path(@goal) }
format.json { render json: @goal.errors, status: :unprocessable_entity }
end
end
private
def set_goal
@goal = Goal.find(params[:id])
end
#category_ids:[] needs to be added back to goal_params when they're added back in
def goal_params
params.require(:goal).permit(:goalname, :goaldesc, :goalhow, :goalwhy, :goalreward, :goalduedate, :goalstatus )
end
def goal_review_params
params.require(:goal).permit(:goaldifficult, :goallearned, :goalnext)
end
View:
<%= form_for (@goal) do |form| %>
<div class="col-md-12 goalform">
<%= form.label :goaldifficult, value: "Name your Goal" %><br>
<%= form.text_field :goaldifficult, :rows => 2, style: 'width:80%;',
placeholder: "...'" %>
</div>
<div class="col-md-12 goalform">
<%= form.label :goallearned, value: "Name your Goal" %><br>
<%= form.text_field :goallearned, :rows => 2, style: 'width:80%;',
placeholder: "...'" %>
</div>
<div class="col-md-12 goalform">
<%= form.label :goalnext, value: "Name your Goal" %><br>
<%= form.text_field :goalnext, :rows => 2, style: 'width:80%;',
placeholder: "...'" %>
</div>
<div class="col-md-12 goalform">
<%= form.submit class:"btn btn-primary" %>
</div>
Routes:
resources :goals do
...
member do
get 'goal_completed', to: 'goals#goal_completed', as: 'goal_completed'