私はこれで初心者であり、価値がないと知っていますが、誰かが私に説明してください。ここに私がしたことがあります。私は自分のデータベースのために私の既存のレールアプリに新しいマイグレーションを生成し、マイグレーションは "プロファイル"と呼ばれています。 db:migrateを実行し、以前の "new.html.erb"フォームを編集しました。これは私の意見/ユーザー/ new.hmtl.erbある私のレールアプリにNo Method Errorが表示されるのはなぜですか?
undefined method `major' for #<User:0x00000100b6e030>
Extracted source (around line #23):
20: </div>
21: <div class="field">
22: <%= f.label :"major" %><br />
23: <%= f.text_field :major %>
24: </div>
:
class CreateProfiles < ActiveRecord::Migration
def self.up
create_table :profiles do |t|
t.string :major
t.string :year
t.string :books_sell
t.string :books_buy
t.string :facebook
t.string :restaurants
t.string :interests
t.timestamps
end
add_index :profiles, :major
add_index :profiles, :year
add_index :profiles, :books_sell
add_index :profiles, :books_buy
add_index :profiles, :facebook
add_index :profiles, :restaurants
add_index :profiles, :interests
end
def self.down
drop_table :profiles
end
end
基本的に、私は私のアプリにプロファイルセクションを追加していますが、私はこれを取得しています:コードは次のようになります。ファイル:
<h1>Sign up</h1>
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
<div class="field">
<%= f.label :"year" %><br />
<%= f.text_field :year %>
</div>
<div class="field">
<%= f.label :"major" %><br />
<%= f.text_field :major %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
何が欠けていますか?
あなたのフォームは 'User'モデルのためのもので、あなたのマイグレーションは' Profile'モデルのものでした。これはあなたの問題だろうか? –
@Benoit Garret、私はあなたがその場に出たと思う。私はそれを調べます。 – Tony
真剣に、初心者であることをお詫びしないでください。このスレッドでは初心者の質問について読む:http://meta.stackexchange.com/questions/97327/can-i-ask-newbie-and-basic-questions-in-stack-overflow –