def new_for_apartment
hobo_new_for :apartment do
if params[:apartment_id]
@aptm=Apartment.find(:first, :conditions=> ["id
= ?",params[:apartment_id] ])
original = Address.find(:first, :conditions=> ["building_id
= ?",@aptm.building_id])
this = @address= original.clone
else
@address.attributes = params[:address] || {}
hobo_ajax_response if request.xhr?
end
end
end
Here with the raise this.inspect i can see that all values as they are
expected (with values from building address) but renders blank fields
as a new form and not with the expect values.
:(
Any ideia?
On Mar 29, 9:45 pm, Daniel M <[email protected]> wrote:
> Hi, thank you for your attention.
>
> The class represents one Address, and an address can belongs to a
> Building, Apartment or a Person, to implement that concept i
> successful used the belongs_to
>
> class Address < ActiveRecord::Base
>
> hobo_model # Don't put anything above this
>
> fields do
> street :string
> nr :string
> floor :integer
> postal_code :integer
> latitude :string
> longitude :string
> timestamps
> end
>
> belongs_to :person
> belongs_to :building
> belongs_to :apartment
>
> belongs_to: city
> belongs_to: country
>
> end
>
> Now, if i have a address of a building and i create a new address for
> an apartment on that building i will want to load automatically a new
> form but with the same data (on certain fields) of the building
> address, because the address of the apartment will have the same city
> and the same country and street name.
>
> class Building < ActiveRecord::Base
>
> hobo_model # Don't put anything above this
>
> fields do
> name :string
> timestamps
> end
>
> has_many :address #(implemented as has_one)
> has_many :apartments
>
> end
>
> class Apartment < ActiveRecord::Base
>
> hobo_model # Don't put anything above this
>
> fields do
> name :string
> timestamps
> end
>
> has_one :address
> belongs_to :building
> belongs_to :person
>
> end
>
> The idea was to implement at the Address controller on the action
> new_for apartment that logic to bring some values to the new address
> for apartment form heredited from the building address.
>
> def new_for_apartment
> hobo_new_for :apartment do
> if params[:apartment_id]
> �...@aptm=apartment.find(:first, :conditions=> ["id
> = ?",params[:apartment_id] ])
> original = Address.find(:first, :conditions=> ["building_id
> = ?",@aptm.building_id])
> this = @morada= original.clone
> else
> �[email protected] = params[:address] || {}
> hobo_ajax_response if request.xhr?
> end
> end
> end
>
> Any ideas?
>
> Thanks.
>
> On Mar 29, 6:47 pm, Matt Jones <[email protected]> wrote:
>
>
>
> > On Mar 28, 2010, at 11:56 AM, Daniel M wrote:
>
> > > :(
>
> > > Does not work...
>
> > > Maybe is because I have a new_for action
>
> > > def new_for_fraccao
> > > hobo_new_for :fraccao do
> > > if params[:fraccao_id]
> > > @fraccao=Fraccao.find(:first, :conditions=> ["id
> > > = ?",params[:fraccao_id] ])
> > > original = Morada.find(:first, :conditions=> ["imovel_id
> > > = ?",@fraccao.imovel_id])
> > > this = @morada= original.clone
> > > else
> > > @morada.attributes = params[:morada] || {}
> > > hobo_ajax_response if request.xhr?
> > > end
> > > end
> > > end
>
> > My first guess would be that cloning 'original' is messing up the
> > logic that detects where to send the form data to - the object won't
> > have new_record? set, for instance. You'll probably want to grab the
> > object already in 'this' (set up by hobo_new_for) and fill in any
> > parameters that you need.
>
> > HOWEVER, in this case it seems like there's a code smell here; typical
> > DB normalization rules mean there shouldn't *be* any data to copy in
> > this situation. Can you provide more detail on your models?
>
> > Thanks,
>
> > Matt Jones
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" 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/hobousers?hl=en.