RoR 的新手。我正在制作一个简单的博客来发布音乐条目。我有两个模型 Tune 和 Artist ,其中一个曲调属于一个艺术家。我正在使用 simple_form 来呈现我的表单。我遇到的问题是 simple_form 正在提取正确的关联,但是当我单击提交时,它没有正确保存关联并且验证没有通过。代码如下:
课程
class Tune < ActiveRecord::Base
belongs_to :artist
validates :artist, presence: true
end
class Artist < ActiveRecord::Base
has_many :tunes
end
数据库架构
ActiveRecord::Schema.define(version: 20131027190309) do
create_table "artists", force: true do |t|
t.string "name"
t.string "real_name"
t.string "gender"
t.string "city"
t.string "country"
t.string "artist_soundcloud_link"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "tunes", force: true do |t|
t.string "soundcloud_link"
t.string "download_link"
t.string "download_label"
t.string "name"
t.string "style"
t.boolean "mix"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "artist_id"
end
add_index "tunes", ["artist_id"], name: "index_tunes_on_artist_id"
end
我的表格
<%= simple_form_for @tune, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :name %>
<%= f.input :soundcloud_link %>
<%= f.input :download_label %>
<%= f.input :download_link %>
<%= f.input :mix %>
<%= f.association :artist%>
<%= f.button :submit %>
<% end %>