当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - undefined method `reservefunctionrooms' for #<Reservation:0xb637f24c>

问题描述:

hi im new in rails and starting a reservation app using ruby 1.9 and rails 3.2.1

one of my action seems to fail with a error

undefined method `reservefunctionrooms' for #<Reservation:0xb637f24c>

i dont know where it did wrong but i think i did everything right

my route.rb

 resources :reservations do

resources :reservefunctionrooms

end

my controller

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

my model reservefunctionroom.rb

 belongs_to :functionroom

belongs_to :reservation

my functionroom.rb

 has_many :reservefunctionrooms

my view 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 %>

error stack

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'

the app doesn't do much yet it just create a reservation entry

the error points at new if anything else needed just ask me thanks all more power to us

regards led

网友答案:

You need to add has_many :reservefunctionrooms to your reservation model.

分享给朋友:
您可能感兴趣的文章:
随机阅读: