On 12 July 2011 15:54, Rodrigo Ruiz <rodrigo.ru...@gmail.com> wrote:

Could you not top post please, it makes it difficult to follow the
thread.  Insert your comments at appropriate points in previous
message.  Thanks.

> If I do the same as the 196 episode it works, but I want a has_one and
> belongs_to relationship, no has_many.
> With has_one it doesn't work. If I set all to singular form (the names of
> model I mean) I get this error:
>
> NoMethodError in CompaniesController#new
>
> undefined method `build' for nil:NilClass
>
> I got company and company_contact models
> Company model:
>    has_one :company_contact, :dependent => :destroy
>    accepts_nested_attributes_for :company_contact
> CompaniesController:
>   def new
>     @company = Company.new
>     @company.company_contact.build

I have not done this but looking at the docs [1], for a has_one
relationship I think you need to do
@company.build_company_contact

Colin

[1] 
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

>   end
> CompanyContact model:
>   belongs_to :company
> views/companies/new:
>   <% f.fields_for :company_contact do |company_contact_form| %>
>      <div class='field'>
>   <%= company_contact_form.label 'Nome do responsável por Marketing' %>
>   <%= company_contact_form.text_field :marketing_name %>
>      </div>
>   <% end %>
>
>
> On Tue, Jul 12, 2011 at 10:15 AM, Colin Law <clan...@googlemail.com> wrote:
>>
>> On 12 July 2011 05:13, Rodrigo Ruiz <rodrigo.ru...@gmail.com> wrote:
>> > It uses a method called 'build', which says (to me at least) that it
>> > doesn't
>> > exist.
>>
>> Show us the exact error and the code around the failing line.
>>
>> Colin
>>
>> >
>> > On Mon, Jul 11, 2011 at 10:15 PM, Everaldo Gomes
>> > <everaldo.go...@gmail.com>
>> > wrote:
>> >>
>> >> Take a look in these screencasts:
>> >> http://railscasts.com/episodes?utf8=%E2%9C%93&search=model
>> >> http://railscasts.com/episodes/196-nested-model-form-part-1
>> >> http://railscasts.com/episodes/197-nested-model-form-part-2
>> >> Maybe they can help you.
>> >> Best regards,
>> >> Everaldo
>> >>
>> >> On Mon, Jul 11, 2011 at 10:11 PM, Hassan Schroeder
>> >> <hassan.schroe...@gmail.com> wrote:
>> >>>
>> >>> On Mon, Jul 11, 2011 at 5:55 PM, Rodrigo Ruiz
>> >>> <rodrigo.ru...@gmail.com>
>> >>> wrote:
>> >>> > Problem is I want more than one model as I explained before.
>> >>>
>> >>> So each "step" is a different page, different model -- again, what is
>> >>> the issue? Complete one, go to the next.
>> >>>
>> >>> --
>> >>> Hassan Schroeder ------------------------ hassan.schroe...@gmail.com
>> >>> http://about.me/hassanschroeder
>> >>> twitter: @hassan
>> >>>
>> >>> --
>> >>> 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@googlegroups.com.
>> >>> To unsubscribe from this group, send email to
>> >>> rubyonrails-talk+unsubscr...@googlegroups.com.
>> >>> For more options, visit this group at
>> >>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>> >>>
>> >>
>> >> --
>> >> 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@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> rubyonrails-talk+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/rubyonrails-talk?hl=en.
>> >
>> > --
>> > 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@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > rubyonrails-talk+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/rubyonrails-talk?hl=en.
>> >
>>
>> --
>> 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@googlegroups.com.
>> To unsubscribe from this group, send email to
>> rubyonrails-talk+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>
>
> --
> 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@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>

-- 
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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to