No route matches [POST] “/articles/new”

前端 未结 7 1682
余生分开走
余生分开走 2020-12-31 09:57

When I try to submit the form its giving me the error

No route matches [POST] \"/articles/new\"

the files are: new.html.erb
this file

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 10:37

    Your actions/methods in the controller do nothing. It should be something like:

    class ArticlesController < ApplicationController
    
      def new 
        @article = Article.new
      end
    
      def create 
        @article = Article.new(article_params)
        if @article.save
          redirect_to @article
        else
          render 'new'
        end
      end
    
     private
    
      def article_params
        params.require(:article).permit()# here go you parameters for an article
      end
    
    end
    

    In the view:

    <%= form_for @article do |f| %>
    

提交回复
热议问题