Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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 回形针宝石不上传文件_Ruby On Rails_Ruby On Rails 4_Paperclip - Fatal编程技术网

Ruby on rails 回形针宝石不上传文件

Ruby on rails 回形针宝石不上传文件,ruby-on-rails,ruby-on-rails-4,paperclip,Ruby On Rails,Ruby On Rails 4,Paperclip,好的,所以我已经搜索了很多关于这个问题的答案,我想我只是错过了一些明显的东西,但我是RoR的新手,所以请容忍我 我用的是回形针,宝石安装得很好。我一直在遵循关于railscasts的教程,我完全遵循了说明,但它不起作用 我猜这是因为不同版本的rails和一些与强参数有关的东西?我想上传一张食谱上传图片。正如我所检查的那样,数据库迁移工作正常,并且所有相关列都存在 包括以下所有内容: recipe.rb文件: _recipe_form.html.erb文件: 编辑: 增加 迁移 谢谢你的帮助。在这

好的,所以我已经搜索了很多关于这个问题的答案,我想我只是错过了一些明显的东西,但我是RoR的新手,所以请容忍我

我用的是回形针,宝石安装得很好。我一直在遵循关于railscasts的教程,我完全遵循了说明,但它不起作用

我猜这是因为不同版本的rails和一些与强参数有关的东西?我想上传一张食谱上传图片。正如我所检查的那样,数据库迁移工作正常,并且所有相关列都存在

包括以下所有内容:

recipe.rb文件: _recipe_form.html.erb文件: 编辑: 增加

迁移
谢谢你的帮助。在这件事上我设法得到了一些外界的帮助。这是一个简单的修复,我相信你会发现,如果我显示了参数

我忘了在我的参数中添加:image,如下所示

params.require(:recipe).permit(:name, :description, :live, :image)

都修好了。谢谢大家!

您是否收到任何错误?生产中还是本地?提供一些背景。抱歉@SimoneCarletti,不,我可以填写表格,选择一张图片并提交。表单仍然有效并添加到数据库中,但是图像文件从未上载,如果我检查数据库,图像列中没有任何信息。添加回形针后是否重新启动服务器?是的,我尝试过。你知道自从rails 4以来回形针的使用是否发生了变化吗?你能添加你的配方参数方法和你的迁移吗?
<%= form_for(@recipe, :html => { :multipart => true }) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <div class="field">
    <%= f.text_field :name, placeholder: "My Recipe" %>
  </div>
  <div class="field">
    <%= f.text_area :description, placeholder: "Write a description..." %>
  </div>
  <div class="field">
    <%= f.file_field :image %>
  </div>
  <%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
def create
  @recipe = current_user.recipes.build(recipe_params)
  if @recipe.save
    flash[:success] = "Recipe Created!"
    redirect_to @recipe
  else
    @feed_items = []
    render 'new'
  end
end
class AddAttachmentImageToRecipes < ActiveRecord::Migration
  def self.up
    change_table :recipes do |t|
      t.attachment :image
    end
  end

  def self.down
    drop_attached_file :recipes, :image
  end
end
@recipe = Recipe.find(params[:id])
params.require(:recipe).permit(:name, :description, :live, :image)