• Development of a web blog on Ruby on Rails

    Right now, we're pointing the form to an update action, which isn't defined yet, but we'll do that soon.

     

    Passing an article object to the method will automatically generate a url to submit the edited article form. This option tells Rails that we want this form to be submitted using PATCH, an HTTP method that is expected to be used to update resources according to the REST protocol.

     

    The form_with arguments can be model objects, such as model: @article , which will cause the helper to populate the form with the object's fields. Passing a symbol (scope: :article) to the namespace just creates the fields, but doesn't populate them with anything. Read more in the form_with documentation.

     

    Next, we need to create an update action in app/controllers/articles_controller.rb. Add it between the create action and the private method:

     

    def create

      @article = Article.new(article_params)

     

      if @article.save

        redirect_to @article

      else

        render 'new'

      end

    end


    Tags Tags : , ,