Hi Ryan,
Try this out
<% form_for :room, :url => { :action => :add_room, :id => @house } do
|form| %>
<%= form.label :name, "Name of room: " %>
<%= form.text_field :name %>
/* Differentiate lights parameter using following way */
<%= text_field :light,:number_of_lights, :size => 2 %><br />
<%= text_field :light, :wattage, :size => 2 %><br />
<% end %>
And in your controller do the following
def add_room
@house = House.find(params[:id])
@room = Room.new(params[:room])
@light = Light.new(params[:light])
respond_to do |format|
## Save all the parameter only if they are valid, if any of your
object is not pass validation then no one of the below get saved.
if @room.valid? && @light.valid? && @house.valid? && @room.save
&& @light.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
try it & let me know if u face any problem
Thanks,
Salil Gaikwad
--
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 [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
-~----------~----~----~----~------~----~------~--~---