2012-03-27 62 views
0

喜IM我做了一個靜態頁面,我的我的預訂 應用程序的功能室都顯示,並且可以添加在的 reservation_function_room(線項目預訂functionroom)它 提出了未初始化常量預訂時曾經我對<%= link_to "add functionrooms", reservation_pages_functionroom_path(@reservation) %>路線不能在此先感謝弄清楚什麼是錯 非常感謝未初始化的常量預訂

頁面靜態頁面

class PagesController < ApplicationController 

    def functionroom 
    @reservation = Reservation.find(params[:reservation_id]) 
    @function_room = FunctionRoom.all 
    end 
end 

functionroom.html.erb

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

    <h1>functionRooms</h1> 
    <%@function_room.each do |functionroom|%> 
    <h3><%= functionroom.name%></h3> 
    <p><%= number_to_currency(functionroom.price)%></p> 
    <%= button_to 'add function room', 
reservation_reservation_function_room_path(:function_room_id => 
functionroom), :method => :post,:remote => true%> 
    <%end%> 

reservation_contoller.rb

def index 
    @reservations = Reservation.all 
    end 

    def show 
    @reservation = Reservation.includes(:reservation_function_rooms => 
:function_room,:reservation_package => :package).find(params[:id]) 
    end 

class ReservationFunctionRoomsController < InheritedResources::Base 
def show 
    @reservation_function_room = 
ReservationFunctionRoom.find(params[:id]) 
end 


def new 
    @reservation_function_room = ReservationFunctionRoom.new 
end 

def create 
    @reservation = Reservation.find(params[:reservation_id]) 
    function_room = FunctionRoom.find(params[:function_room_id]) 
    @reservation_function_room = 
@reservation.add_function_room(function_room.id) 

    if @reservation_function_room.save 
    redirect_to @reservation, :notice => "function room successfuly 
added" 
    end 
end 
end 

路由

get "pages/menu" 

    resources :reservation_function_rooms 




    resources :services 

    resources :reservations do 
    get "pages/functionroom" 
    end 

    resources :reservation_packages 

    resources :package_line_items 


    resources :packages do 
    resources :package_crews 
    end 

    resources :function_rooms 

reservation.rb

class Reservation < ActiveRecord::Base 
    has_one :reservation_package 
    belongs_to :service 
    has_many :reservation_function_rooms 
    has_many :package_line_items 
    has_many :menus , :through => :package_line_items, :uniq => true 
    has_many :function_rooms, :through =>:reservation_function_rooms 

    def add_function_room(function_room_id) 
    current_function_room = 
reservation_function_rooms.find_by_function_room_id(function_room_id) 
    if current_function_room 
     redirect_to @reservation, :notice => "function room already 
added" 
    else 
    current_function_room = 
reservation_function_rooms.build(:function_room => function_room_id) 
    current_function_room.price = 
current_function_room.function_room.price 
    end 
    current_function_room 
    end 

end 

預訂/ show.html.erb

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

<p> 
    <b>Name:</b> 
    <%= @reservation.name %> 
</p> 

<%= display_package @reservation%> 
<p> 
    <b>Address:</b> 
    <%= @reservation.address %> 
</p> 

<p> 
    <b>Contact:</b> 
    <%= @reservation.contact %> 
</p> 

<p> 
    <b>Date:</b> 
    <%= @reservation.date %> 
</p> 

<p> 
    <b>Timestart:</b> 
    <%= @reservation.timeStart %> 
</p> 

<p> 
    <b>Timeend:</b> 
    <%= @reservation.timeEnd %> 
</p> 

<p> 
    <b>Numguest:</b> 
    <%= @reservation.numGuest %> 
</p> 

<p> 
    <%= link_to "add functionrooms", reservation_pages_functionroom_path(@reservation) %> 
</p> 



<table> 
    <tr> 
     <th>Function room</th> 
     <th>Price</th> 
    </tr> 
    <% @reservation.reservation_function_rooms.each do |room|%> 
    <tr> 
     <td><%= room.function_room.name%></td> 
     <td><%= room.function_room.price%></td> 
    </tr> 



<%end%> 


</table> 





<%= link_to 'Edit', edit_reservation_path(@reservation) %> | 
<%= link_to 'Back', reservations_path %> 

如果還有什麼需要隨時提出在此先感謝:)

+0

沒有輸入完整的細節,我可以看到你的代碼中的一個巨大的錯誤。你在MODEL裏有這樣一行,你不能這樣做:'redirect_to @reservation ...' – Zheileman 2012-03-27 12:42:04

+0

我已經嘗試刪除該行,甚至不使用add_functionromm方法,但它仍然是相同的答覆 – Led 2012-03-27 12:50:14

+0

'uninitialized constant Reservations'告訴我,在你的代碼中的某處你可能有一個類型,並且試圖調用預留的類方法而不是保留(你的模型名稱)。我會在您的代碼中進行全球搜索以查找「預訂」,並查找您引用「預訂」而不是「預訂」的位置。 – 2012-03-27 13:11:33

回答

0

我知道這已經4年了,但是我遇到了同樣的問題,我想我可能已經找到它來自哪裏。

你必須依賴「HAS_ONE:reservation_package」 ,並降低你的「資源:reservation_packages」

我認爲「S」現在的問題是:要麼做一個單一的資源或關係的has_many。那爲什麼他找不到它。 這就是我如何解決我的問題。

相關問題