Justin Doshay
Justin Doshay

Reputation: 109

how to add multiple entries to an event

I am trying to add bands to an event, all my other strings, etc work fine but when i try to add bands, nothing comes up.

here is my 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
      t.time :doors
      t.time :showtime
      t.string :age
      t.string :price
      t.text :description

      t.timestamps null: false
    end
  end
end

add_band_to_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

schema.rb:

  create_table "gigs", force: :cascade do |t|
    t.string   "venue_name"
    t.string   "event"
    t.date     "date"
    t.time     "doors"
    t.time     "showtime"
    t.string   "age"
    t.string   "price"
    t.text     "description"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
    t.integer  "user_id"
    t.string   "band"
    t.string   "band1"
    t.string   "band2"
    t.string   "band3"
    t.string   "band4"
    t.string   "band5"
    t.string   "band6"
    t.string   "band7"
    t.string   "band8"
  end

updated add_band_to_gigs.rb:

class AddBandToGigs < ActiveRecord::Migration
  def change
    add_column :gigs, :band, :string
  end
end

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 model:

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

i have tried running db:migrate, it runs fine but when i go to the create event page, all the info fills in upon post but nothing shows for bands. Any ideas?

Upvotes: 1

Views: 48

Answers (1)

steve klein
steve klein

Reputation: 2629

You are adding database columns to your table, not adding data to it. Look into db:seeds as one way to seed your database for testing. You can also just create small amounts of test data using the Rails console.

Just for posterity, the issue turned out to be that the index and show actions and view were tangled up. Once the index action controlled the correct view, it worked fine.

Upvotes: 1

Related Questions