Ruby on Rails Tuesday, March 27, 2012

hi im having a bit trouble in my application im new in ROR development
i made a static page where my function rooms of my reservation
application are showed and can be add in in the
reservation_function_room(line item of reservation functionroom) it
raises uninitialized constant Reservations cant figure out whats wrong
very thanks in advance thanks

page-static pages
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
------------------------------
routes

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

if anything is needed feel free to ask thanks in advance :)

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment