0
嘿,這可能是一個非常簡單的問題,但我似乎無法讓我的show.html.erb頁面顯示,我是一個真正的初學者。這是在軌道上的紅寶石。這裏是我的代碼:Ruby on Rails顯示嵌入式模型
Post.rb
class Post < ActiveRecord::Base
attr_accessible :artist
has_many :songs
end
Song.rb
class Song < ActiveRecord::Base
attr_accessible :lyric, :name, :song_id
belongs_to :post
end
CreatePost遷移
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :artist
t.string :song
t.timestamps
end
end
end
CreateSong遷移
class CreateSongs < ActiveRecord::Migration
def change
create_table :songs do |t|
t.text :lyric
t.string :name
t.integer :song_id
t.timestamps
end
end
end
show.html.erb
<center><h1><%= @post %></h1></center>
<p> Songs: </p>
<% @post.song.song_id.each do |s| %>
<p>
<%= s.name %>
</p>
<% end %>
<% form_for [@post, Song.new] do |f| %>
<p>
<%= f.label :name, "Artist" %><br />
<%= f.text_field :name %><br />
<%= f.label :body, "Song Name:" %><br />
<%= f.text_field :body %>
</p>
<p>
<%= f.submit "Add Song" %>
</p>
<% end %>