首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >#<Reservation:0xb637f24c>的未定义方法` `reservefunctionrooms‘

#<Reservation:0xb637f24c>的未定义方法` `reservefunctionrooms‘
EN

Stack Overflow用户
提问于 2012-03-03 03:00:16
回答 1查看 194关注 0票数 0

您好,我是rails新手,正在使用Ruby1.9和rails 3.2.1启动一个预订应用程序

我的一项操作似乎因错误而失败

代码语言:javascript
复制
undefined method `reservefunctionrooms' for #<Reservation:0xb637f24c>

我不知道哪里做错了,但我想我做的一切都是对的

我的route.rb

代码语言:javascript
复制
 resources :reservations do
    resources :reservefunctionrooms 
  end

我的控制器

代码语言:javascript
复制
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

代码语言:javascript
复制
  belongs_to :functionroom
  belongs_to :reservation

我的functionroom.rb

代码语言:javascript
复制
  has_many :reservefunctionrooms

我的视图resevefunctionroom/new.html.erb

代码语言:javascript
复制
<h1>New reservefunctionroom</h1>

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

<%= link_to 'Back', reservefunctionrooms_path %>

_form.html.rb

代码语言:javascript
复制
<%= 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 %>

错误堆栈

代码语言:javascript
复制
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'

这个应用程序做的并不多,但它只是创建了一个预订条目,错误点在new,如果需要任何其他东西,只要问我就可以了,感谢我们所有的力量

关于led

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-03 03:18:15

您需要在reservation模型中添加has_many :reservefunctionrooms

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9538871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档