努力通过铁路协会创造记录

时间:2014-09-29 14:13:49

标签: ruby-on-rails ruby activerecord

class PhotosController < ApplicationController
def new
end
  def create
    @shoot = Shoot.find(params[:id])
  @photo = @shoot.photos.build(photo_params)
  @photo.save   
  end
def edit
end
  def destroy
 end
    def photo_params
      params.require(:photo).permit(:name)
    end
end

这会从我的拍摄控制器收到一个帖子请求。我在show admin视图中显示此表单。然而,id不会在params中继承。拍摄控制器动作如下。

def showadmin
  @name=(params[:shootName])
 @shoot=Shoot.find_by(name: @name)
  @photos = @shoot.photos

  @photoform = @shoot.photos.build

我已经在这里工作了几个小时,无法理解如何通过关联创建记录。

class Photo < ActiveRecord::Base
    belongs_to :shoot
 validates :shoot_id, presence: true
end

 class Shoot < ActiveRecord::Base
has_many :photos, dependent: :destroy
end

        Ali::Application.routes.draw do
  root  'static_pages#home'
  resources :shoots
  resources :photos
 match '/gallery', to: 'static_pages#gallery',    via: 'get'
 match '/about',   to: 'static_pages#about',   via: 'get'
 match '/contact', to: 'static_pages#contact', via: 'get'
 match '/shoots', to: 'shoots#show', via: 'get'
 match '/shoots/showadmin/:shootName', to: 'shoots#showadmin', via: 'get'

 match '/photos/:shootName', to: 'shoots#photos', via: 'get'
 match '/show', to: 'shoots#show', via: 'get'
 get '/shoots/go/:catagory', to: 'shoots#show'
 match '/index', to: 'shoots#index', via: 'get'

0 个答案:

没有答案