David Heinemeier Hansson wrote:> > 1)
> > I have a controller called "houses".  In that,
there''s an action called
> > "modify".  modify''s view (modify.rhtml) has a form
with an action
> > "save_house".  When the user hits submit, modify gets called
with id
> > save_house (i.e. /houses/modify/save_house).  What I want to have 
> > happen is
> > the action "save_house" called.  I have another action
"new", and
> > new.rhtml
> > has a form with action "create_house", and when the user
hits submit,
> > the
> > action "create_house" is called, which is what I want to
have happen.
> > I''m
> > not sure why that''s not the case with modify.
> 
> It sounds like you''re using scaffolding, which had a problem
regarding
> this in Rails 0.8.5. You can fix it manually by doing something like:
> 
> <%= form("house", :action => url_for(:action =>
"save_house")) %>
> 
> ..if my guess at what your problem is have any grounding in reality. 
> This problem is fixed in the very forthcoming (and massive) Rails 0.9 
> upgrade.
That seems to be it.  Thanks!
> 
> > 2)
> > has_and_belongs_to_many question:  I have a model "House"
that
> > has_and_belongs_to_many "Amenity".  Is there a "Best
Way(tm)" to
> > display
> > this relationship in the controller/view?  The way it works currently:
> >
> > house_controller#create:
> 
> @house = House.new(@params["house"].save
> @house.amenities << Amenities.find(@params["amenities"])
I get the following error:
ActiveRecord::AssociationTypeMismatch in Houses#save_house
Amenity expected, got Amenities
The code:
if @house.save
      @house.amenities <<  Amenities.find(@params["amenities"])
if
@params["amenities"]
> 
> Amenities.find accepts and array and will return a such. 
> @house.amenities.<< does the same and creates a link between the
house
> and amenity for each of the records found.