I have an articles route in my project. I created a Post model. I don't know if there are conflicts in that This is my code:
class PagesController < ApplicationController
def articles
@posts = Post.all
end
def new
@post = Post.new
end
def show
@post = Post.find(params[:id])
end
def create
@post = @Post.new(post_params)
@post.save
redirect_to article_path(@post)
end
def contacts
end
private
def post_params
params.require(:post).permit(:title, :author, :body)
end
end
This is my error:
ActionController::ParameterMissing in PagesController#create
param is missing or the value is empty: post
Extracted source (around line #35):
def post_params
params.require(:post).permit(:title, :author, :body)
end
This my routes file:
Rails.application.routes.draw do root 'pages#index' get 'about', to: 'pages#about' get 'services', to: 'pages#services' get 'articles', to: 'pages#articles' get 'articles/new', to: 'pages#new' get 'articles/:id', to: 'pages#show', as: 'article' post 'articles', to: 'pages#create' get 'contacts', to: 'pages#contacts' end
Aucun commentaire:
Enregistrer un commentaire