레일 시작 안내서를 따라 가려고합니다. 기사 대신 주식을 사용하고 코멘트 대신 TimeDeltas를 사용합니다. 내가보기에 갈 때 지금이 오류가 계속중첩 된 클래스 만들기 'show - 오류 발생'StocksController #에서 ActiveRecord :: StatementInvalid 표시 'time_deltas'테이블을 찾을 수 없음
# 쇼 찾을 수 없습니다 액티브 :: StatementInvalid StocksController에테이블 'time_deltas'
라인: @time_delta = @ stock.time_deltas.build
Heres는 내보기 : Heres는
<h1> Stock </h1>
<table>
<tr>
<th>Stock</th>
<th>Hashtag</th>
</tr>
<tr>
<td><%= @stock.name %></td>
<td><%= @stock.hashtag %></td>
</tr>
</table>
<h2>Deltas: </h2>
<table>
<tr>
<th>Stock</th>
<th>Hashtag</th>
</tr>
<% @stock.deltas.each do |delta| %>
<tr>
<td><%= @delta.start %></td>
<td><%= @delta.length %></td>
</tr>
<% end %>
</table>
<h2>Add a TimeDelta:</h2>
<%= form_for([@stock, @stock.time_deltas.build]) do |f| %>
<p>
<%= f.label :start %><br>
<%= f.text_field :start %>
</p>
<p>
<%= f.label :length %><br>
<%= f.text_area :length %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
<%= link_to 'Back', stocks_path%>
<%= link_to 'Edit', edit_stock_path(@stock)%>
내 주식 컨트롤러 :
class StocksController < ApplicationController
def new
@stock = Stock.new
end
def index
@stocks = Stock.all
end
def create
# XXX Add columns for delta and current standing when we get there
# they can intiate to nil
@stock = Stock.new(stock_params)
if @stock.save
redirect_to @stock
else
render 'new'
end
end
def show
@stock = find_stock
@time_delta = @stock.time_deltas.build
end
def edit
@stock = find_stock
end
def update
@stock = find_stock
if @stock.update(stock_params)
redirect_to @stock
else
render 'edit'
end
end
def destroy
@stock = find_stock
@stock.destroy
redirect_to stocks_path
end
private
def stock_params
params.require(:stock).permit(:name, :hashtag)
end
def find_stock
return Stock.find(params[:id])
end
end
Heres는 내가뿐만 아니라없이-소용 어떤 제안을 내 마이그레이션을 실행 재 시도했습니다
class TimeDeltasController < ApplicationController
def new
@stock = Stock.find(params[:stock_id])
@time_delta = @stock.time_deltas.build
# respond_with(@stock, @time_delta)
end
def create
@stock = Stock.find(time_delta_params)
@time_delta = @stock.time_deltas.create(params[:stock])
redirect_to stock_path(@stock)
end
private
def time_delta_params
params.require(:time_delta).permit(:start, :length)
end
end
내 TimeDelta 컨트롤러?
편집 : 두 모델 재고 :
class Stock < ActiveRecord::Base
has_many :deltas
has_many :time_deltas
validates :hashtag, :name , presence: true, :uniqueness => true, length: { minimum: 2 }
end
시간 델타 :
class TimeDelta < ActiveRecord::Base
belongs_to :stock
end
데이터베이스 스키마 : 당신은 "마이그레이션을 통해 이름을 테이블을 생성
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140412204548) do
create_table "delta", force: true do |t|
t.datetime "start"
t.integer "length"
t.integer "stock_id"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "delta", ["stock_id"], name: "index_delta_on_stock_id"
create_table "queries", force: true do |t|
t.text "tweet"
t.integer "tweetId"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "stocks", force: true do |t|
t.text "name"
t.text "hashtag"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "time_delta", force: true do |t|
t.datetime "start"
t.integer "length"
t.integer "stock_id"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "time_delta", ["stock_id"], name: "index_time_delta_on_stock_id"
end
모델을 표시하십시오 .. –
@OscarValdezEsquea가 둘 다 추가되었습니다! – NNNNNNNNNNDelicious
time_deltas라는 테이블이 있습니까? –