خرید بک لینک

Vote count: 0

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?

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 9 خرداد 1395 ساعت: 17:39

صفحه بندی