> On Feb 9, 2018, at 5:01 PM, fugee ohu <fugee279@gmail.com> wrote:
>
>
>
> On Thursday, February 8, 2018 at 12:23:43 PM UTC-5, Walter Lee Davis wrote:
> That validation was probably on the person, not the picture, unless you added validates_associated to the Person class.
>
> Look at this: https://github.com/walterdavis/fugee/blob/master/app/controllers/people_controller.rb#L74
>
> and this:
>
> https://github.com/walterdavis/fugee/blob/master/app/views/people/_form.html.erb#L25
>
> The rest is scaffolded, there's nothing mysterious here.
>
> Clone this to your machine, run it in rails server.
>
> Go to localhost:3000/pictures and add some pictures (just file names).
>
> Go to localhost:3000/people, and add some people.
>
> See how you can choose pictures for each person? See how the association is saved and updated? Watch in the console as the record is saved or updated from the web.
>
> Walter
>
> > On Feb 8, 2018, at 11:36 AM, fugee ohu <fuge...@gmail.com> wrote:
> >
> > I created an update action in the persons controller Valitadation was failing with :name can't be blank so I assumed @person.save was trying to create a new picture That's why I moved the action from the pictures controller to the persons controller and changed the action to @person.update instead of @person.save Did you already understand that?
>
> Do I have to create routes like "get '/people/:id/addresses' => 'addresses#index', as: 'person_addresses' I was thinking maybe rails already creates those routes from the associations and if I make them explicit maybe I'll mess up the routes
>
Rails would make those if you had nested routes:
resources :people do
resources :addresses
end
That will require you to do some additional changes in your addresses controller -- knowing that you will always have a person_id attribute running around in all actions, for example.
Read the relevant Rails guide (routing, I think).
Walter
--
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/4844BF10-7DF1-4D4D-96A4-E2710628AE7D%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment