Following various parts of the inteet, I have the following code:
Controller
class StudiesController < ApplicationController
def new
require_user
@study = Study.new
end
def create
@study = Study.new(study_params)
if @study.save
flash[:success] = "You made it!"
redirect_to root_path
else
flash[:danger] = "Uh oh—something went wrong"
redirect_to study_path
end
end
end
View
<%= form_for(@study, url: {action: :create}, class: "study-form") do |f| %>
<%= f.text_field :title %><br>
<div class="btn-submit">
<%= f.submit "I studied today!", class: "btn btn-primary margin-top" %>
</div>
<%= end %>
It works, but my question is: Why do I need Study.new called twice? Why do I call it in create if I've already called it in new?
