嘿,这可能是一个非常简单的问题,但我似乎无法显示我的 show.html.erb 页面,而且我是一个真正的初学者。这是用红宝石制成的。这是我的代码:
Post.rb
class Post < ActiveRecord::Base
attr_accessible :artist
has_many :songs
end
歌曲.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
显示.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 %>