Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails controller,因为此文件不存在,而且应该存在,因为cars控制器创建了一个新的garage对象,并将属性插入garage模型。虽然在这两种模型中都不需要附加了文件,但我想知道您正在使用什么gem/code来处理上传。从has_attached_fi_Ruby On Rails_Ruby_Devise_Paperclip_Strong Parameters - Fatal编程技术网

Ruby on rails controller,因为此文件不存在,而且应该存在,因为cars控制器创建了一个新的garage对象,并将属性插入garage模型。虽然在这两种模型中都不需要附加了文件,但我想知道您正在使用什么gem/code来处理上传。从has_attached_fi

Ruby on rails controller,因为此文件不存在,而且应该存在,因为cars控制器创建了一个新的garage对象,并将属性插入garage模型。虽然在这两种模型中都不需要附加了文件,但我想知道您正在使用什么gem/code来处理上传。从has_attached_fi,ruby-on-rails,ruby,devise,paperclip,strong-parameters,Ruby On Rails,Ruby,Devise,Paperclip,Strong Parameters,controller,因为此文件不存在,而且应该存在,因为cars控制器创建了一个新的garage对象,并将属性插入garage模型。虽然在这两种模型中都不需要附加了文件,但我想知道您正在使用什么gem/code来处理上传。从has_attached_file方法中,我感觉这是一个回形针。假设您使用的是回形针或类似的gem,使用的是什么服务?您是如何为存储配置它的?我的带有附加文件的模型明确说明了storage::fog(我们使用Rackspace云文件作为CDN)。嗨,Craig,我使用的是回


controller,因为此文件不存在,而且应该存在,因为
cars
控制器创建了一个新的
garage
对象,并将属性插入
garage
模型。虽然在这两种模型中都不需要
附加了文件
,但我想知道您正在使用什么gem/code来处理上传。从
has_attached_file
方法中,我感觉这是一个回形针。假设您使用的是回形针或类似的gem,使用的是什么服务?您是如何为存储配置它的?我的带有附加文件的模型明确说明了
storage::fog
(我们使用Rackspace云文件作为CDN)。嗨,Craig,我使用的是
回形针
gem。我的所有迁移都已加载,我相信我的关联是正确的。我没有使用服务。我在笔记本电脑上本地部署了一个开发环境。
class CarsController < ApplicationController
  before_action :set_car

  def show
    @garage = Garage.find(params[:id])
  end

  def create    
    @garage = Garage.create( tech_id:  @car.service.tech.id, :customer_id: current_customer.id )
    if @garage.save
      redirect_to techs_path, notice:  "You car has been added to the garage!" 
    elsif 
      redirect_to tech_path, notice:  "Uh oh, flat tire!" 
    end
  end

  private

  def set_car
    @car = Car.find(params[:id])
  end

  def garage_params
    params.permit(:tech_id, :customer_id )
  end

end
class Car < ActiveRecord::Base
  belongs_to :service
  belongs_to :tech #added 5/27

  has_attached_file :garage_photo, styles: { medium: "300x300>", :thumb => "100x100>" }#, :default_url => "/images/:style/missing.png"
  validates_attachment_content_type :garage_photo, content_type: /\Aimage\/.*\Z/
end
class Garage < ActiveRecord::Base

  belongs_to :customer
  belongs_to :tech

  has_attached_file :garage_photo, styles: { medium: "300x300>", :thumb => "100x100>" }#, :default_url => "/images/:style/missing.png"
  validates_attachment_content_type :garage_photo, content_type: /\Aimage\/.*\Z/

end
<h2>Please review to add to garage </h2>
<b>Your garage tech:</b> <%= @car.service.tech.id %><br>
<b>ID:</b> <%= current_customer.id %><br>

<%= form_for @garage, :html => { :multipart => true } do |f| %>
  <%= f.file_field :garage_photo %>
<% end %>


<%= button_to 'Add to Garage', tech_cars_path(tech_id: @car.service.tech.id, id: @car.id) %>
<%= link_to 'Back to tech', tech_path(@car.service.tech.id) %>
Rails.application.routes.draw do
  devise_for :customers, controllers: { sessions: 'customers/sessions' }, :path => ''
  devise_for :techs, controllers: { sessions: 'techs/sessions' } 
  #, :path => ''#, :path_names => { :sign_in => "login", :sign_out => "logout" }

  resources :techs, only: [:index, :show], shallow: true do
    resources :cars, only: [:show, :create]
  end

  resources :service_menus, :services, :garages
    root to: "home#index"
end
class AddAttachmentGaragePhotoToGarages < ActiveRecord::Migration
  def change
    change_table :garages do |t|
      t.attachment :garage_photo
    end
  end
end
| garage_photo_updated_at   | datetime     | YES  |     | NULL    |                |
| garage_photo_file_size    | int(11)      | YES  |     | NULL    |                |
| garage_photo_content_type | varchar(255) | YES  |     | NULL    |                |
| garage_photo_file_name    | varchar(255) | YES  |     | NULL  
class CarsController < ApplicationController
  before_action :set_car

  def show
    @garage = Garage.find(params[:id])
  end

  def create    
    @garage = Garage.create(garage_params)
    if @garage.save
      redirect_to techs_path, notice:  "You car has been added to the garage!" 
    elsif 
      redirect_to tech_path, notice:  "Uh oh, flat tire!" 
    end
  end

  private

  def set_car
    @car = Car.find(params[:id])
  end

  def garage_params
    params.permit(:tech_id, :customer_id, :garage_photo )
  end
end
<h2>Please review to add to garage </h2>
<b>Your garage tech:</b> <%= @car.service.tech.id %><br>
<b>ID:</b> <%= current_customer.id %><br>

<%= form_for @garage, :html => { :multipart => true } do |f| %>
  <%= f.hidden_field :tech_id, value: @car.service.tech.id %>
  <%= f.hidden_field :customer_id, value: current_customer.id %>
  <%= f.file_field :garage_photo %>
<% end %>

<%= button_to 'Add to Garage', tech_cars_path(tech_id: @car.service.tech.id, id: @car.id) %>
<%= link_to 'Back to tech', tech_path(@car.service.tech.id) %>