Я не уверен, почему, но я не могу сохранить введенные данные в базу данных, и пока не могу найти ответ :), но он работает для создания сообщений с помощью консоли.
Started POST "/posts" for 127.0.0.1 at 2018-05-23 14:04:32 +0300
Processing by PostsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"B19yVi1jHtg7068SKFbI3tj28THNdfgGYwUSN+e79Vt/o0ivDUl0D4i71PuLKlZf1wxnEJMVnp+GmH/HcxE6cQ==", "post"=>{"category_id"=>"2", "title"=>"asfaf", "content"=>"asfkja", "photo_cache"=>""}, "commit"=>"Create Post"}
Unpermitted parameter: :photo_cache
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
(0.5ms) BEGIN
Category Load (0.5ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
(0.4ms) ROLLBACK
<%= simple_form_for(@post) do |f| %>
<%= f.collection_select(:category_id, Category.all, :id, :name, {prompt: "Choose a category" }) %><br>
<%= f.label :title %><br>
<%= f.text_field :title, placeholder: "Type the post title here" %><br>
<%= f.label :content %><br>
<%= f.text_area :content, placeholder: "Type the post text here" %><br>
<%= f.input :photo %>
<%= f.input :photo_cache, as: :hidden %><br>
<%= f.submit %>
<% end %>
def new
@post = Post.new
authorize @post
end
def create
@post = Post.new(post_params)
authorize @post
if @post.save
redirect_to @post, notice: "The post was created!"
else
render 'new'
end
end
def post_params
params.require(:post).permit(:title, :content, :category_id, :photo, :user_id)
end
class Post < ApplicationRecord
validates :title, :content, :category_id, presence: true
belongs_to :category
belongs_to :user
mount_uploader :photo, PhotoUploader
end