jeudi 13 août 2015

Pass ID of parent to new association - rails

Trying to pass the ID from the Edit action view

on the form I have

   <h1>Editing Video</h1>

<%= render 'form' %>

<br>
<%= link_to 'New Poster', new_poster_path %> | 
<%= link_to 'Show', @video %> |
<%= link_to 'Back', videos_path %>

While the user is on the edit form for video I want them to be able to edit the posters that belong to the video (has_many :posters)

On the Edit action of the video controller I added

@poster = Poster.new

when the user clicks the new poster link they are directed to the new poster and can upload an image

when I create the record - it doesn't pass the ID of the video.

I have in my model for the posters

belongs_to :video

so I don't know how I am safely supposed to pass the ID of the video edit I was on to the newly created poster.

table Posters id poster_url video_id <-- this should have the id of the video I was just editing...

Routes:

 Rails.application.routes.draw do
      resources :posters
      resources :people

      resources :profiles
      devise_for :users

      resources :videos do
        resources :posters
      end

      # The priority is based upon order of creation: first created -> highest priority.
      # See how all your routes lay out with "rake routes".

      # You can have the root of your site routed with "root"
       root 'home#index'



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire