###前提・実現したいこと
RailsでSNSのようなサイトを作成中で、Carrierwaveで画像アップロード機能を追加したいです。
導入手順としてはRailsチュートリアルの13章を参考に進めていますが、下記のエラーが解決できません。
初歩的な質問で申し訳ありませんがご教授よろしくお願い致します。
※下記のプロジェクトとは別に、ブログなどを参考に手順通りcarrierwaveのサンプルを作成しましたが
そちらは問題なく動作しています。
※自分のプロジェクトに機能追加する時に上手くいきません。
carrierwaveのカスタマイズについても理解が浅いので、
他におすすめのやり方があれば合わせて教えていただけると幸いです。
【URL】
Railsチュートリアル13章13-4
https://railstutorial.jp/chapters/user_microposts?version=5.1#sec-micropost_images
###発生している問題・エラーメッセージ
ActionController::ParameterMissing at /sample/myprofileedit
param is missing or the value is empty: accounts
(paramが見つからないか、値が空です)
###該当のソースコード
◆【sample_controller.rb】
class SampleController < ApplicationController protect_from_forgery layout 'application' before_action :authenticate_account!, only: [:login_check,:profilepage] before_action :logged_in_user, only: [:create, :destroy] before_action :correct_user, only: :destroy def myprofileedit @accounts = Accounts.new(accounts_params) end def show end def new end def login_check @account = current_account @msg = @account.current_sign_in_at.to_s end private def accounts_params params.require(:accounts).permit(:picture)←エラー発生箇所 end def correct_user @accounts = current_user.microposts.find_by(id: params[:id]) redirect_to root_url if @accounts.nil? end end
◆【myprofileedit.html.erb】追加部分のみ抜粋
<div> <%= form_for(@accounts) do |f| %> <%= render 'shared/error_messages', object: f.object %> <div class="field"> <%= f.text_area :content, placeholder: "Compose new micropost..." %> </div> <%= f.submit "Post", class: "btn btn-primary" %> <span class="picture"> <%= f.file_field :picture %> </span> <% end %> </div>
◆【schema.rb】
ActiveRecord::Schema.define(version: 20171213075642) do create_table "accounts", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "picture" t.index ["email"], name: "index_accounts_on_email", unique: true t.index ["reset_password_token"], name: "index_accounts_on_reset_password_token", unique: true end end
###補足情報(言語/FW/ツール等のバージョンなど)
Ruby on Rails 5.1.4
Ruby2.3.3
あなたの回答
tips
プレビュー