В настоящее время я работаю над более старым проектом, созданным StephenFiser (https://github.com/StephenFiser/FrogBlog), для целей обучения и посмотрим, как можно улучшить свои навыки (решение проблем и отладка). Я попытался добавить Active Storage For Uploads Upload toВ проекте не было загрузки файла изображения, за исключением gravatar_image_url. Поэтому я попытался использовать активное хранилище. Проект работал хорошо, прежде чем я попытался добавить активное хранилище. Теперь я добавил активное хранилище и выполнил миграцию. Пожалуйста, что яЯ здесь пробовал все возможные решения и вопросы, которые мог найти в Интернете.
Но затем, когда я пытаюсь добавить новое сообщение с панели автора, я получаю следующее:
create
app / controllers / авторы / posts_controller.rb, строка 39
34 end
35 # POST / posts
36 # POST /posts.json
37 38 def create
39 @post = current_author.posts.new (post_params)
40
41 response_to do | format |
42 if@ post.save
43 format.html {redirect_tohors_post_path (@post), уведомление: «Сообщение успешно создано.»}
44 format.json {render: show, status:: созданный, местоположение: @post}
Post Model
Класс Posthas_one_attached: image
PER_PAGE = 3
область действия: most_recent ->, -> (page) {most_recent.paginate (page: page, per_page: PER_PAGE)} область действия: with_tag, -> (tag) {tagged_with (tag), если tag.present?}
scope: list_for, -> (страница, тег) действительно недавний (страница) .with_tag (тег) end
def should_generate_new_friendly_id?title_changed?end
def display_day_published если Опубликовал_at.present?"Опубликовано # {Опубликовал_at.strftime ('% - b% -d,% Y')}" иначе "Еще не опубликовано."end end
def публикует обновление (опубликовано: true, publ_at: Time.now) end
def отменяет публикацию обновления (публикуется: false, publ_at: nil) end
end
Post Controller * модуль 1054 * Класс авторов PostsController # GET /posts
# GET /posts.json
def index
@posts = current_author.posts.most_recent
end
# GET /posts/1
# GET /posts/1.json
def show
end
# GET /posts/new
def new
@post = current_author.posts.new
end
# GET /posts/1/edit
def edit
end
def publish
@post.publish
redirect_to authors_posts_url
end
def unpublish
@post.unpublish
redirect_to authors_posts_url
end
# POST /posts
# POST /posts.json
def create
@post = current_author.posts.new(post_params)
respond_to do |format|
if @post.save
format.html { redirect_to authors_post_path(@post), notice: 'Post was successfully created.' }
format.json { render :show, status: :created, location: @post }
else
format.html { render :new }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /posts/1
# PATCH/PUT /posts/1.json
def update
respond_to do |format|
if @post.update(post_params)
format.html { redirect_to authors_post_path(@post), notice: 'Post was successfully updated.' }
format.json { render :show, status: :ok, location: @post }
else
format.html { render :edit }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.json
def destroy
@post.destroy
respond_to do |format|
format.html { redirect_to authors_posts_url, notice: 'Post was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_post
@post = current_author.posts.friendly.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def post_params
params.require(:post).permit(:title, :body, :description, :tag_list, :image)
end
конец конец