I'm new to working with rails. I created a article posting form and when I click the post button it brings me to the articles page but it's not posting what I typed.
routes.rb:
get 'articles/new' => 'articles#new'
post 'articles' => 'articles#create'
articles controller:
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def new
@article = Article.new
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to '/articles'
else
render 'new'
end
end
private
def article_params
params.required(:article).permit(:content)
end
end
Aucun commentaire:
Enregistrer un commentaire