エラーが発生しますが、No route matches {:action=>“show”, :controller=>“predictions”}
理由がわかりません。モデルの関係に何か関係があるのではないかと推測しており、ルートを追加する必要があるかもしれません。
予測モデル
class Prediction < ActiveRecord::Base
attr_accessible :fixture_id, :predicted_result
has_one :fixtures, :class_name => 'Fixture', :foreign_key => :fixture_id
belongs_to :fixture
belongs_to :user
end
予測コントローラー
class PredictionsController < ApplicationController
# GET /predictions
# GET /predictions.json
def index
@predictions = Prediction.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @predictions }
end
end
# GET /predictions/1
# GET /predictions/1.json
def show
@prediction = Prediction.find(params[:id])
@fixture = Fixture.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @prediction }
end
end
# GET /predictions/new
# GET /predictions/new.json
def new
@prediction = Prediction.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @prediction }
end
end
# GET /predictions/1/edit
def edit
@prediction = Prediction.find(params[:id])
end
# POST /predictions
# POST /predictions.json
def create
@prediction = Prediction.new(params[:prediction])
respond_to do |format|
if @prediction.save
format.html { redirect_to @prediction, notice: 'Prediction was successfully created.' }
format.json { render json: @prediction, status: :created, location: @prediction }
else
format.html { render action: "new" }
format.json { render json: @prediction.errors, status: :unprocessable_entity }
end
end
end
# PUT /predictions/1
# PUT /predictions/1.json
def update
@prediction = Prediction.find(params[:id])
respond_to do |format|
if @prediction.update_attributes(params[:prediction])
format.html { redirect_to @prediction, notice: 'Prediction was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @prediction.errors, status: :unprocessable_entity }
end
end
end
# DELETE /predictions/1
# DELETE /predictions/1.json
def destroy
@prediction = Prediction.find(params[:id])
@prediction.destroy
respond_to do |format|
format.html { redirect_to predictions_url }
format.json { head :no_content }
end
end
end
ビューを表示
<p id="notice"><%= notice %></p>
<p>
<b>Fixture:</b>
<%= @prediction.fixture_id %>
</p>
<p>
<b>Predicted result:</b>
<%= @prediction.predicted_result %>
</p>
<%= link_to 'Edit', edit_prediction_path(@prediction) %> |
<%= link_to 'Back', predictions_path %>
>rake routes
users_new GET /users/new(.:format) users#new
predictions GET /predictions(.:format) predictions#index
POST /predictions(.:format) predictions#create
new_prediction GET /predictions/new(.:format) predictions#new
edit_prediction GET /predictions/:id/edit(.:format) predictions#edit
prediction GET /predictions/:id(.:format) predictions#show
PUT /predictions/:id(.:format) predictions#update
DELETE /predictions/:id(.:format) predictions#destroy
fixtures GET /fixtures(.:format) fixtures#index
POST /fixtures(.:format) fixtures#create
new_fixture GET /fixtures/new(.:format) fixtures#new
edit_fixture GET /fixtures/:id/edit(.:format) fixtures#edit
fixture GET /fixtures/:id(.:format) fixtures#show
PUT /fixtures/:id(.:format) fixtures#update
DELETE /fixtures/:id(.:format) fixtures#destroy
teams GET /teams(.:format) teams#index
POST /teams(.:format) teams#create
new_team GET /teams/new(.:format) teams#new
edit_team GET /teams/:id/edit(.:format) teams#edit
team GET /teams/:id(.:format) teams#show
PUT /teams/:id(.:format) teams#update
DELETE /teams/:id(.:format) teams#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
root / fixtures#index