Displaying 9 results from an estimated 9 matches for "build_address".
Did you mean:
bind_address
2011 Apr 04
1
Best way to instanciate an empty address element in many nested fields_for
...1) In the view:
f.fields_for :company, @user.company do |company_form|
and company_form.fields_for :address, (address = @user.company.address ?
address : Address.new)
2) In the controller
@user.company.address = Address.new unless @user.company.address
(a variant would be to write @user.company.build_address, which I prefer
over Address.new.)
Do you see other ways and what do you think is best?
Thanks.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6Z...
2006 Jul 20
2
using association properties in form helpers
sorry for the noob question:
how do i reference an association''s properties in a form helper?
e.g. if i wanted to build a select list to choose a user''s address''s
state (user.address.state), how would i hook that to the "method" of
collection_select
collection_select :user, ???, States.find(:all)
2009 Nov 06
0
Nested objects not propagating from view
...pe
accepts_nested_attributes_for :address, {
:allow_destroy => true,
:reject_if => :all_blank
}
end
class Address < ActiveRecord::Base
has_one :contact
has_one :property
belongs_to :state
end
# controller
def new
@user = User.new
@user.build_contact.build_address
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @user }
end
end
def edit
@user = User.find(params[:id])
end
When I run on the console, I can create a new user object with nested
attributes like so:
>> user=User.new
=> #...
2006 Nov 05
0
Forms with associations and collections
...where to make
things work I have to:
1. Create a new Address for the Property.address.
2. If the Address fields are blank the Address record will still be
created.
3. So, I use a custom function to test each value of the hash and
return true if all are blank - only add if false... (i.e.
@property.build_address(params[:address]) unless
params[:address].all_values_are_blank?)
4. If I am updating the property rather than creating it I have to test
whether the address is nil and either update, create or delete
depending on what has been passed in params.
Seems a bit messy and rails always seems to have an e...
2010 Dec 22
1
nested attributes form
Hello!
I have a simple form with a nested attribute (has_one association). Is
works has expected on the new and create actions, the nested attribute
is correctly added in the database.
But when I am on the edit action the nested attributes fields are
empty...
and I am using the same partial for the form.
Am I missing something? Why I don''t get the nested fields displayed?
<%
2010 Nov 28
6
has_one accepts_nested_attributes_for fields_for NOT WORKING HELP
MODEL
class User < ActiveRecord::Base
has_one :address, :dependent => :destroy
accepts_nested_attributes_for :address
end
CONTROL
def new
@user = User.new
@user.build_address # Adicionei
...
VIEW partial _form
....
<% f.fields_for :address do |b| %> # Adicionei
<%= b.text_field :city_manual %> # Adicionei
<% end %> # Adicionei
....
So this is not working... when browser to users/new it do not show th...
2011 Mar 10
4
Multi-model forms
...o basically what I want to do is insert a new guest through guests/
new and insert a row for each model, but the country is handled
through a select_tag instead of inserting a new country.
This is the guest form, with the nested address form view:
<% if @guest.address.nil? %>
<% @guest.build_address %>
<% end %>
<%= form_for(@guest) do |f| %>
<% if @guest.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@guest.errors.count, "error") %> prohibited
this guest from being saved:</h2>
<ul>
&...
2005 Oct 12
4
Validating 2 related models at once not working
Hello,
I have a form that submits data to two related models/tables. One is
Customer the other is Address. Validation for Customer works fine but not
for the Address.
Class Customer < ActiveRecord::Base
has_one :address
validates_presence_of :login, :password, :email
validates_associated :address
end
Class Address < ActiveRecord::Base
belongs_to :customer
validates_presence_of
2010 Feb 16
0
Strange routing(?) Issue
...respond_to do
format.js {
render :update do |page|
page.replace_html "div_map", "<p>Map here</p>"
end
}
end
end
def new
@event = Event.new
address = @event.build_address
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @event }
end
end
# GET /events/1/edit
def edit
@event = Event.find(params[:id])
end
def create
@event = Event.new(params[:event])...