这是我尝试过的:
索引
<%= link_to new_inspiration_path(inspiration: {image: inspiration.image}) %> # user clicks this
控制器
def new
@inspiration = current_user.inspirations.build(inspiration_params)
end
def inspiration_params
params.require(:inspiration).permit(:name, :image, :image_file_name, :image_content_type, :image_file_size, :image_updated_at)
end
服务器
Started GET "/inspirations/new?inspiration_image=%2Fsystem%2Finspirations%2Fimages%2F000%2F000%2F069%2Foriginal%2Frule_1.jpg%3F1478260961" for 127.0.0.1 at 2016-11-04 08:10:41 -0400
Processing by InspirationsController#new as */*
Parameters: {"inspiration_image"=>"/system/inspirations/images/000/000/069/original/rule_1.jpg?1478260961"} # For example, this is the image url I'm trying to show in the _form
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 129]]
Inspiration Load (0.4ms) SELECT "inspirations".* FROM "inspirations" WHERE "inspirations"."id" IS NULL LIMIT 1
Completed 400 Bad Request in 6ms
_form
<%= simple_form_for(@inspiration, html: { data: { modal: true } }) do |f| %>
<%= image_tag @inspiration.image.url %> # doesn't show image, says "missing"
<%= f.file_field :image %>
<% end %>
模型
class Inspiration < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "300x300>", :small => "150x150>" }
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
belongs_to :user
end
我收到错误: ActionController :: RoutingError(没有路由匹配[GET]“/ images/original/missing.png”):