rails应用程序在用户(场地)位置显示空白区域

时间:2015-04-22 22:45:32

标签: ruby ruby-on-rails-4

我可以发布一个事件但是当我选择要发布的用户时,下拉菜单会显示用户(地点名称)所在的空白区域。我已经尝试了所有我能想到的东西。任何想法都将不胜感激。

我在轨道上4.我也在使用设计。

这是我的档案:

show.html.erb

<p id="notice"><%= notice %></p>

<p>
  <b>Name:</b>
  <%= @gig.user.venue_name %>
</p>

<p>
  <strong>Event:</strong>
  <%= @gig.event %>
</p>

<p>
  <strong>Date:</strong>
  <%= @gig.date %>
</p>

<p>
  <strong>Doors:</strong>
  <%= @gig.doors %>
</p>

<p>
  <strong>Showtime:</strong>
  <%= @gig.showtime %>
</p>

<p>
  <strong>Age:</strong>
  <%= @gig.age %>
</p>

<p>
  <strong>Price:</strong>
  <%= @gig.price %>
</p>

<p>
  <strong>Description:</strong>
  <%= @gig.description %>
</p>

<%= link_to 'Edit', edit_gig_path(@gig) %> |
<%= link_to 'Back', gigs_path %>

index.html.erb

<p id="notice"><%= notice %></p>
<div class="page-header">
  <h1>All Gigs</h1>
</div>

<% @gigs.each do |gig| %>
<div class="gig">
    <strong><%= gig.user.venue_name %></strong>
    <p><%= gig.event %></p>
    <p><%= gig.date %></p>
    <p><%= gig.doors %></p>
    <p><%= gig.showtime %></p>
    <p><%= gig.age %></p>
    <p><%= gig.price %></p>
    <p><%= gig.description %></p>
    <div class="meta">
      <%= link_to time_ago_in_words(gig.created_at) + " ago", gig %>
      <span class="admin">
        | <%= link_to 'Edit', edit_gig_path(gig) %> |
        <%= link_to 'Delete', gig, method: :delete, data: { confirm: 'Are you sure?' } %>
      </span>
    </div>
</div>
<% end %>
  </tbody>
</table>

gig.rb

class Gig < ActiveRecord::Base
  belongs_to :user
end

user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

has_many :gigs

end

_form.html.erb

<%= simple_form_for(@gig, html: {class: "form-horizontal"}) do |f| %>
  <% if @gig.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@gig.errors.count, "error") %> prohibited this gig from being saved:</h2>

      <ul>
      <% @gig.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <%= f.input :user_id, collection: User.all, label_method: :venue_name %>
  <%= f.input :event %>
  <%= f.input :date %>
  <%= f.input :doors %>
  <%= f.input :showtime %>
  <%= f.input :age %>
  <%= f.input :price %>
  <%= f.input :description %>
  <div class="form-actions">
    <%= f.button :submit %>
  </div>

db migrate将用户ID添加到gig

class AddUserIdToGigs < ActiveRecord::Migration
  def change
    add_column :gigs, :user_id, :integer
    add_index :gigs, :user_id
    remove_column :gigs, :name
  end
end

gigs_controller.rb

class GigsController < ApplicationController
  before_action :set_gig, only: [:show, :edit, :update, :destroy]

  # GET /gigs
  # GET /gigs.json
  def index
    @gigs = Gig.all
  end

  # GET /gigs/1
  # GET /gigs/1.json
  def show
  end

  # GET /gigs/new
  def new
    @gig = Gig.new
  end

  # GET /gigs/1/edit
  def edit
  end

  # POST /gigs
  # POST /gigs.json
  def create
    @gig = Gig.new(gig_params)

    respond_to do |format|
      if @gig.save
        format.html { redirect_to @gig, notice: 'Gig was successfully created.' }
        format.json { render :show, status: :created, location: @gig }
      else
        format.html { render :new }
        format.json { render json: @gig.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /gigs/1
  # PATCH/PUT /gigs/1.json
  def update
    respond_to do |format|
      if @gig.update(gig_params)
        format.html { redirect_to @gig, notice: 'Gig was successfully updated.' }
        format.json { render :show, status: :ok, location: @gig }
      else
        format.html { render :edit }
        format.json { render json: @gig.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /gigs/1
  # DELETE /gigs/1.json
  def destroy
    @gig.destroy
    respond_to do |format|
      format.html { redirect_to gigs_url, notice: 'Gig was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_gig
      @gig = Gig.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def gig_params
      params.require(:gig).permit(:name, :event, :date, :doors, :showtime, :age, :price, :description, :user_id)
    end
end

1 个答案:

答案 0 :(得分:0)

解决了它:

运行irb后,我注意到db中的场地为空。因此,我意识到我必须通过创造新的形式来设计场所。