Ruby on rails 4 如何向事件添加多个条目
我正在尝试为一个活动添加乐队,我的所有其他弦乐等都很好,但当我尝试添加乐队时,什么都没有出现 这是我的create gigs.rb:Ruby on rails 4 如何向事件添加多个条目,ruby-on-rails-4,Ruby On Rails 4,我正在尝试为一个活动添加乐队,我的所有其他弦乐等都很好,但当我尝试添加乐队时,什么都没有出现 这是我的create gigs.rb: class CreateGigs < ActiveRecord::Migration def change create_table :gigs do |t| t.string :venue_name t.string :event t.date :date t.string :band
class CreateGigs < ActiveRecord::Migration
def change
create_table :gigs do |t|
t.string :venue_name
t.string :event
t.date :date
t.string :band
t.time :doors
t.time :showtime
t.string :age
t.string :price
t.text :description
t.timestamps null: false
end
end
end
更新了将乐队添加到gigs.rb:
class AddBandToGigs < ActiveRecord::Migration
def change
add_column :gigs, :band1, :string
add_column :gigs, :band2, :string
add_column :gigs, :band3, :string
add_column :gigs, :band4, :string
add_column :gigs, :band5, :string
add_column :gigs, :band6, :string
add_column :gigs, :band7, :string
add_column :gigs, :band8, :string
end
end
class AddBandToGigs < ActiveRecord::Migration
def change
add_column :gigs, :band, :string
end
end
class AddBandToGigs
show.html.erb:
<div class="page-header">
<h2>My Gigs</h2>
</div>
<% if @gigs %>
<% @gigs.each do |gig| %>
<div class="well">
<p><%= gig.date %></p>
<p><%= gig.event %>: $<%= gig.price %></p>
<p><%= gig.band %></p>
<p><%= gig.age %> | <%= gig.doors %> / <%= gig.showtime %></p>
<p><%= gig.description %></p>
<hr />
<%= link_to time_ago_in_words(gig.created_at), gig_path(gig) %> ago
</div>
<% end %>
<% end %>
我的演出
:$
|/
以前
Gig.all:
Gig Load (1.0ms) SELECT "gigs".* FROM "gigs"
Gig Load (1.0ms) SELECT "gigs".* FROM "gigs"
=> #<ActiveRecord::Relation [#<Gig id: 1, venue_name: nil, event: "Gigitt Launch Party", date: "2015-01-06", doors: "2000-01-01 19:00:00", showtime: "2000-01-01 21:00:00", age: "21+", price: "8", description: "Rock Your Hear Out!", created_at: "2015-05-01 21:20:46", updated_at: "2015-05-01 21:20:46", user_id: 1, band: "thrice">, #<Gig id: 2, venue_name: nil, event: "4th of July Festival", date: "2015-04-07", doors: "2000-01-01 13:00:00", showtime: "2000-01-01 21:00:00", age: "All Ages", price: "31", description: "Going To Be A Blast!", created_at: "2015-05-01 21:20:46", updated_at: "2015-05-01 21:20:46", user_id: 2, band: "pennywise">, #<Gig id: 4, venue_name: nil, event: "this is a test event", date: "2015-05-01", doors: "2000-01-01 21:30:00", showtime: "2000-01-01 21:30:00", age: "All Ages", price: "31", description: "testtest", created_at: "2015-05-01 21:31:08", updated_at: "2015-05-01 21:31:08", user_id: 1, band: nil>]>
Gig加载(1.0ms)从“Gig”中选择“Gig”。*
Gig加载(1.0ms)从“Gig”中选择“Gig”。*
=> #
gig模型:
class Gig < ActiveRecord::Base
belongs_to :user
validates :description, presence: true,
length: { minimum: 8 }
validates :event, presence: true,
length: { maximum: 20 }
validates :age, presence: true
validates :price, presence: true,
length: { minimum: 1 },
length: { maximum: 8 }
validates :user_id, presence: true
end
class-Gig
我试过运行db:migrate,它运行得很好,但是当我转到创建事件页面时,所有的信息都会在post中填写,但是对于乐队没有显示。有什么想法吗?您是在向表中添加数据库列,而不是向表中添加数据。查看
db:seeds
,将其作为测试数据库种子的一种方法。您还可以使用Rails控制台创建少量测试数据
就为了子孙后代,问题变成了索引
和显示
操作和视图被纠缠在一起。一旦索引操作控制了正确的视图,它就工作得很好
class Gig < ActiveRecord::Base
belongs_to :user
validates :description, presence: true,
length: { minimum: 8 }
validates :event, presence: true,
length: { maximum: 20 }
validates :age, presence: true
validates :price, presence: true,
length: { minimum: 1 },
length: { maximum: 8 }
validates :user_id, presence: true
end