Ruby on Rails Monday, October 20, 2014

Thank you so much Mr. Sampath. I solved the problem. I forget that  i should used the instance of the customer
 [def create
@customer = Customer.find(params[:customer_id])
@project = Customer.projects.create(project_params)
end] .. 

 It should be 

 [def create
@customer = Customer.find(params[:customer_id])
@project = @customer.projects.create(project_params)
end] .. 

:D is it okay to you sir if I ask some question if I can't resolve some problem or become my mentor. I want to learn more in rails 4. :)  

On Mon, Oct 20, 2014 at 10:05 AM, Sampath Munasinghe <sampathnisha@gmail.com> wrote:
Use customer has_many: :projects
accepts_nested_attributes_for :projects

and then make customer view to handle project data or  ( if u need above approach ) add customer id to above _form.html. 

if u need further help, please let me know. :)

On Sat, Oct 18, 2014 at 11:43 PM, Colin Law <clanlaw@gmail.com> wrote:
On 18 October 2014 15:09, Pepeng Agimat <eebasadre20@gmail.com> wrote:
> Good day, I'm a beginner in rails I already develop a simple app in rails
> but i want to upgrade the app to be an ajax, I already created the first
> model customer but in the second model project where customer has many
> projects and project belongs_to customer, those ajax form modal that i copy
> in a tutorial didn't work. I experiencing some error in CRUD in project
> part.. I'm not familiar in nested resources and the Ajax part.
>
> this is the error: "ActiveRecord::RecordNotFound (Couldn't find Customer
> without an ID):
>   app/controllers/projects_controller.rb:14:in `create'"
>
> ...
> def create
> @customer = Customer.find(params[:customer_id])

I guess that params[:customer_id] is null.  Check in development.log
and you will see what parameters are being posted.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvura5TnA%3DZTh6ajPxNcDNiCORnrZUcd4LGmHdB%3DCpbLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAJgSRnZbdvNbyCUk%2BVRJaGaqnL2H0W25yBcpAh%3DSoSfsFLvSxw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPmpWec_CGKM1M%2B6ghu7k1xQgaMgrs78NQQ7ZPKjbyEgH9Em2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment