未定义的方法`reservefunctionrooms'用于#<预订:0xb637f24c> </reservation:0xb637f24c>

时间:2012-03-02 19:00:16

标签: ruby-on-rails ruby ruby-on-rails-3

嗨,我在rails中使用ruby 1.9和rails 3.2.1

启动预订应用程序

我的某个操作似乎因错误而失败

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

my 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 个答案:

答案 0 :(得分:1)

您需要将has_many :reservefunctionrooms添加到reservation模型中。