Thanks for all the help so far. I believe I'm starting to understand
things now. The part above is working great. However, I have a
controller called calculator which is the only part that will be
accessible to users. From calculator you enter information about the
house, then that information is saved to house and you can then start
adding rooms, have a house_id attribute that needs to be passed from
the house that was just created.
The problem now is that I can't get the new room stuff to render from
calculator. It always complains it can't find the partials (which are
located under app/views/rroms). If I change the paths for them to be
found, it causes other errors.
Here is the calculator_controller. save_house is called when the user
submits the form. The commented line under "if @house.save" is what I
had originally. The line under that is my attempt to fix these
problems.
----------------------------------------
class CalculatorController < ApplicationController
def index
end
def save_house
@house = House.new(params[:house])
respond_to do |format|
if @house.save
#format.html { render :action => 'add_rooms', :id => @house }
format.html { render :template => '/rooms/new', :room_id =>
@house.id }
format.xml { render :xml => @house, :status
=> :created, :location => @house }
else
format.html { render :action => 'index' }
format.xml { render :xml => @house.errors, :status
=> :unprocessable_entity }
end
end
end
def add_rooms
@house = House.find(params[:id])
@rooms = Room.find_by_house_id(@house.id)
rescue ActiveRecord::RecordNotFound
logger.error("Attempt to access invalid house #{params[:id]}")
flash[:notice] = "You must create a house before adding rooms"
redirect_to :action => 'index'
end
def add_room
@house = House.find(params[:id])
@room = Room.new(params[:room])
respond_to do |format|
#if @room.valid? && @light.valid? && @house.valid? && @room.save
&& @light.save && @house.add_room(@room) && @house.save
if @room.save
@house.add_room(@room)
@house.save
flash[:notice] = "Room \"#[email protected]}\" was successfully
added."
format.html { render :action => 'add_rooms' }
format.xml { render :xml => @room, :status
=> :created, :location => @room }
else
format.html { render :action => 'add_rooms' }
format.xml { render :xml => @room.errors, :status
=> :unprocessable_entity }
end
end
rescue ActiveRecord::RecordNotFound
logger.error("Attempt to access invalid house #{params[:id]}")
flash[:notice] = "You must create a house before adding a room"
redirect_to :action => 'index'
end
def report
flash[:notice] = nil
@house = House.find(params[:id])
@rooms = Room.find_by_house_id(@house.id)
rescue ActiveRecord::RecordNotFound
logger.error("Attempt to access invalid house #{params[:id]}")
flash[:notice] = "You must create a house before generating a
report"
redirect_to :action => 'index'
end
end
----------------------------------------
Preferably I'd like to be able to render add_rooms (see below), which
is just the same partial called form room.new with a list of rooms
above and a button to move on below.
----------------------------------------
<div id="addRooms">
<p>House id is <%= @house.id %></p>
<h3>Your rooms:</h3>
<% if @house.rooms %>
<ul>
<% for room in @house.rooms %>
<li>
<%= h room.name %> has <%= h room.number_of_bulbs %>
<%= h room.wattage_of_bulbs %> watt bulbs, in use for
<%= h room.usage_hours %> hours per day.
</li>
<% end %>
</ul>
<% else %>
<p>You have not added any rooms yet</p>
<% end %>
<%= render :partial => 'rooms/room_form' %>
<br />
<%= button_to "Continue to report", :action => "report", :id =>
@house %>
</div>
----------------------------------------
Thanks,
Ryan
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---