質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

1448閲覧

ActiveModel::UnknownAttributeErrorを解決したい

utsu001

総合スコア1

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/12/20 09:58

ActiveModel::UnknownAttributeErrorを解決したい

ここに質問の内容を詳しく書いてください。
rubyでprotospace実装をしています

発生している問題・エラーメッセージ

ActiveModel::UnknownAttributeError in PrototypesController#update unknown attribute 'title' for User.

該当のソースコード

コントローラー

ruby

1class PrototypesController < ApplicationController 2 def index 3 @prototypes = Prototype.all 4 end 5 6 def new 7 @prototype = Prototype.new 8 end 9 10 def create 11 @prototype = Prototype.create(prototype_params) 12 if @prototype.save 13 redirect_to root_path 14 else 15 render prototypes: :form 16 end 17 end 18 19 def show 20 @prototype = Prototype.find(params[:id]) 21 end 22 23 def edit 24 @prototype = Prototype.find(params[:id]) 25 end 26 27 def update 28 if current_user.update(prototype_params) 29 redirect_to prototype_path(prototype.id), method: :get 30 else 31 render :edit 32 end 33 end 34 35 private 36 def prototype_params 37 params.require(:prototype).permit(:title, :catch_copy, :concept, :image).merge(user_id: current_user.id) 38 end 39end 40

モデル

class Prototype < ApplicationRecord validates :title, presence: true validates :catch_copy, presence: true validates :concept, presence: true validates :image, presence: true belongs_to :user has_one_attached :image end
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable validates :name, presence: true validates :profile,presence: true validates :occupation, presence: true validates :position, presence: true has_many :prototypes end

マイグレーション

class CreatePrototypes < ActiveRecord::Migration[6.0] def change create_table :prototypes do |t| t.string :title, null: false t.text :catch_copy, null: false t.text :concept, null: false t.references :user, foreign_key: true t.timestamps end end end
# frozen_string_literal: true class DeviseCreateUsers < ActiveRecord::Migration[6.0] def change create_table :users do |t| ## Database authenticatable t.string :name, null: false t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" t.text :profile, null: false t.text :occupation, null: false t.text :position, null:false ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable # 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 ## Confirmable # t.string :confirmation_token # t.datetime :confirmed_at # t.datetime :confirmation_sent_at # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at t.timestamps null: false end add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true # add_index :users, :confirmation_token, unique: true # add_index :users, :unlock_token, unique: true end end

試したこと

同じエラーでrails db:migrateをして解決した方がした方がいたので試しましたが変わらずエラーが出ました

補足情報(FW/ツールのバージョンなど)

ruby

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問