2012-03-27 17 views
0

hallo im ein wenig Mühe in meiner Anwendung neu im in ROR Entwicklung mit habe ich eine statische Seite, wo meine Funktion Zimmer meiner Reservierung Anwendung zeigte und reservation_function_room im hinzufügen in sein (Position von Reservierung functionroom) es wirft nicht initialisierte konstante Reservierungen wann immer ich Route zu <%= link_to "add functionrooms", reservation_pages_functionroom_path(@reservation) %> kippt, was falsch heraus sehr dank im Voraus danknicht initialisierte Konstante Reservierungen

Seite statische Seiten

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 

Routen

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 

Reservierung/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 %> 

, wenn etwas frei benötigt wird, fühlen Dank im Voraus zu fragen :)

+0

Ohne ins Detail zu gehen, kann ich einen großen Fehler in Ihrem Code sehen. Sie haben diese Zeile in einem MODEL, etwas, was Sie nicht tun können: 'redirect_to @reservation ...' – Zheileman

+0

Ich habe bereits versucht, diese Zeile zu entfernen und auch nicht die add_functionromm-Methode verwenden, aber es ist immer noch gleich danke für die Antwort – Led

+0

Die 'nicht initialisierten konstanten Reservierungen 'sagen mir, dass Sie irgendwo in Ihrem Code einen Typ haben und versuchen, eine Klassenmethode für Reservierungen anstatt für Reservierung (Ihren Modellnamen) aufzurufen. Ich würde Ihren Code für die "Reservierungen" global suchen und nach einem Ort suchen, an dem Sie auf "Reservierungen" und nicht auf "Reservierungen" verweisen. –

Antwort

0

Ich weiß, dass es schon 4 Jahre her ist, aber ich habe das selbe Problem durchgespielt und ich denke ich Vielleicht haben Sie herausgefunden, woher es kommt.

Sie haben Abhängigkeit „has_one: reservation_package“ und senken Sie „Ressourcen: reservation_packages“

Ich denke, die „s“ ist hier das Problem: Entweder tun eine einzelne Ressource oder eine has_many Beziehung. Deshalb kann er es nicht finden. So habe ich mein Problem behoben.

Verwandte Themen