2012-03-02 64 views
0

喜即時通訊新和使用Ruby 1.9和3.2.1軌道未定義的方法`reservefunctionrooms'爲#<預約:0xb637f24c>在軌

我的一個動作,似乎失敗了錯誤

開始預訂應用程序
undefined method `reservefunctionrooms' for #<Reservation:0xb637f24c> 

我不知道它在哪裏做錯了,但我認爲我做的一切權利

我route.rb

resources :reservations do 
    resources :reservefunctionrooms 
    end 

我的控制器

class ReservefunctionroomsController < ApplicationController 
    # GET /reservefunctionrooms 
    # GET /reservefunctionrooms.json 
    def index 
    #@reservefunctionrooms = Reservefunctionroom.all 
    redirect_to Reservation.find(params[:reservation_id]) 
    respond_to do |format| 
     format.html # index.html.erb 
     format.json { render json: @reservefunctionrooms } 
    end 
    end 

    # GET /reservefunctionrooms/1 
    # GET /reservefunctionrooms/1.json 
    def show 
    #@reservefunctionroom = Reservefunctionroom.find(params[:id]) 
    redirect_to Reservation.find(params[:reservation_id]) 

    respond_to do |format| 
     format.html # show.html.erb 
     format.json { render json: @reservefunctionroom } 
    end 
    end 

    # GET /reservefunctionrooms/new 
    # GET /reservefunctionrooms/new.json 
    def new 
    #@reservefunctionroom = Reservefunctionroom.find(params[:id]) 
    @reservation = Reservation.find(params[:reservation_id]) 
    @reservefunctionroom = @reservation.reservefunctionrooms.build 


    end 

    # GET /reservefunctionrooms/1/edit 
    def edit 
    @reservefunctionroom = Reservefunctionroom.find(params[:id]) 
    end 

    # POST /reservefunctionrooms 
    # POST /reservefunctionrooms.json 
    def create 
    @reservation = Reservation.find(params[:reservation_id]) 
    @reservefunctionroom = @reservation.reservefunctionrooms.build(params[:reservefunctionroom]) 

    respond_to do |format| 
     if @reservefunctionroom.save 
     format.html { redirect_to @reservation, notice: 'Reservefunctionroom was successfully created.' } 
     #format.json { render json: @reservefunctionroom, status: :created, location: @reservefunctionroom } 
     else 
     format.html { render action: "new" } 
     #format.json { render json: @reservefunctionroom.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # PUT /reservefunctionrooms/1 
    # PUT /reservefunctionrooms/1.json 
    def update 
    @reservefunctionroom = Reservefunctionroom.find(params[:id]) 

    respond_to do |format| 
     if @reservefunctionroom.update_attributes(params[:reservefunctionroom]) 
     format.html { redirect_to @reservefunctionroom, notice: 'Reservefunctionroom was successfully updated.' } 
     format.json { head :no_content } 
     else 
     format.html { render action: "edit" } 
     format.json { render json: @reservefunctionroom.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # DELETE /reservefunctionrooms/1 
    # DELETE /reservefunctionrooms/1.json 
    def destroy 
    @reservefunctionroom = Reservefunctionroom.find(params[:id]) 
    @reservefunctionroom.destroy 

    respond_to do |format| 
     format.html { redirect_to reservefunctionrooms_url } 
     format.json { head :no_content } 
    end 
    end 
end 

我的模型reservefunctionroom.rb

belongs_to :functionroom 
    belongs_to :reservation 

我functionroom.rb

has_many :reservefunctionrooms 

我的視圖resevefunctionroom/new.html.erb

<h1>New reservefunctionroom</h1> 

<%= render 'form', :reservation => @reservation, 
    :reservefunctionroom => @reservefunctionroom%> 

<%= link_to 'Back', reservefunctionrooms_path %> 

_form html的。 RB

<%= form_for([reservation,reservefunctionroom]) do |f| %> 
    <% if @reservefunctionroom.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@reservefunctionroom.errors.count, "error") %> prohibited this reservefunctionroom from being saved:</h2> 

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

    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

錯誤堆棧

activemodel (3.2.1) lib/active_model/attribute_methods.rb:407:in `method_missing' 
activerecord (3.2.1) lib/active_record/attribute_methods.rb:126:in `method_missing' 
app/controllers/reservefunctionrooms_controller.rb:30:in `new' 
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
actionpack (3.2.1) lib/abstract_controller/base.rb:167:in `process_action' 
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action' 
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action' 
activesupport (3.2.1) lib/active_support/callbacks.rb:414:in `_run__681443984__process_action__398765339__callbacks' 
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback' 
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' 
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks' 
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_action' 
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action' 
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' 
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument' 
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument' 
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action' 
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in `process_action' 
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process' 
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process' 
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch' 
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' 
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action' 
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call' 
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch' 
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call' 
journey (1.0.3) lib/journey/router.rb:68:in `block in call' 
journey (1.0.3) lib/journey/router.rb:56:in `each' 
journey (1.0.3) lib/journey/router.rb:56:in `call' 
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' 
rack (1.4.1) lib/rack/etag.rb:23:in `call' 
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call' 
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context' 
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call' 
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call' 
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' 
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__651380482__call__1059175300__callbacks' 
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback' 
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks' 
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks' 
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app' 
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call' 
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call' 
rack (1.4.1) lib/rack/runtime.rb:17:in `call' 
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
rack (1.4.1) lib/rack/lock.rb:15:in `call' 
actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call' 
railties (3.2.1) lib/rails/engine.rb:479:in `call' 
railties (3.2.1) lib/rails/application.rb:220:in `call' 
rack (1.4.1) lib/rack/content_length.rb:14:in `call' 
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call' 
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service' 
/home/led/.rvm/rubies/ruby-1.9.3-rc1/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 
/home/led/.rvm/rubies/ruby-1.9.3-rc1/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 
/home/led/.rvm/rubies/ruby-1.9.3-rc1/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 

應用程序並沒有做太多但它只是製造了一個預約條目 在新的誤差點,如果別的需要的只是問我要謝謝更多的權力給我們

關於領導

+1

爲了上帝的愛,請不要將協會稱爲'reservefunctionrooms'。改爲將其稱爲'reserve_function_rooms'。你以後會感謝我。 – 2012-03-02 19:26:00

+0

@RyanBigg好的謝謝你的想法:) – Led 2012-03-02 19:27:34

+0

並感謝您的傾聽。 – 2012-03-02 21:56:44

回答

1

您需要添加has_many :reservefunctionroomsreservation模型。

+0

冬青的廢話,只是即時失蹤謝謝! – Led 2012-03-02 19:22:30

相關問題