I studied the rails tutorial by Michael Hartl and I'd like to add new service to this app.
Although I created new model, controller and views, the following error appeared when I submit f.submit "Create my schedule" in _schedule_form.html.erb.
This error may be caused by strong parameter, I guess.
It would be appreciated if you could give me any suggestion.
development.log
ActionController::ParameterMissing (param is missing or the value is empty: schedule):
app/controllers/schedules_controller.rb:30:in `schedule_params'
app/controllers/schedules_controller.rb:9:in `create'
schedule_controller.rb
class SchedulesController < ApplicationController
before_action :logged_in_user, only: [:create, :destroy]
def new
@schedule = Schedule.new
end
def create
@schedule = current_user.schedules.build(schedule_params)
if @schedule.save
flash[:success] = "schedule created!"
redirect_to root_url
else
render 'new'
end
end
...
private
def schedule_params
params.require(:schedule).permit(:title)
end
end
views\schedules\new.html.erb
<div class="row">
<div class="col-md-12">
<p>Create schedule (<%= current_user.name %>)</p>
<%= render "schedule_form" %>
</div>
</div>
views\schedules\ _schedule_form.html.erb
<%= form_for(@schedule) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="input-group">
<span class="input-group-addon">Title</span>
<input type="text" class="form-control">
</div>
<br>
<%= f.submit "Create my schedule", class: "btn btn-primary" %>
<br>
<% end %>