我使用回形针宝石时,我上传的图片不显示。我收到这个错误:
ActionController :: RoutingError(没有路由匹配[GET]“/handyman_imgs/handyman_index/missing.png”)
这就是我所拥有的:
控制器文件
class HandymenController < ApplicationController
before_action :find_handyman, only: [:show, :edit, :update, :destroy]
def index
if params[:profession].blank?
@handymen = Handyman.all.order("created_at DESC")
else
@profession_id = Profession.find_by(name: params[:profession]).id
@handymen = Handyman.where(:profession_id => @profession_id).order("created_at DESC")
end
end
def show
end
def new
@handyman = current_user.handymen.build
@professions = Profession.all.map{ |p| [p.name, p.id] }
end
def create
@handyman = current_user.handymen.build(handyman_params)
@handyman.profession_id = params[:profession_id]
if @handyman.save
redirect_to root_path
else
render 'new'
end
end
def edit
@professions = Profession.all.map{ |p| [p.name, p.id] }
end
def update
@handyman.profession_id = params[:profession_id]
if @handyman.update(handyman_params)
redirect_to handyman_path(@handyman)
else
render 'edit'
end
end
def destroy
@handyman.destroy
redirect_to root_path
end
private
def handyman_params
params.require(:handyman).permit(:name, :location, :phone_number, :profession_id, :handyman_img)
end
def find_handyman
@handyman = Handyman.find(params[:id])
end
end
模型文件
class Handyman < ActiveRecord::Base
belongs_to :user
belongs_to :profession
has_attached_file :handyman_img, styles: { handyman_index: "250x350>", handyman_show: "325x475>" }
validates_attachment_content_type :handyman_img, content_type: /\Aimage\/.*\Z/
end
错误日志
Started GET "/handyman_imgs/handyman_index/missing.png" for ::1 at 2016-08-15 10:29:24 +0000
ActionController::RoutingError (No route matches [GET] "/handyman_imgs/handyman_index/missing.png"):
actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.6) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.6) lib/rails/engine.rb:518:in `call'
railties (4.2.6) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
C:/Ruby21-x64/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
C:/Ruby21-x64/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
C:/Ruby21-x64/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.0ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (4.0ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (106.1ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (332.3ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (1.0ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (1.0ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (1.0ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.0ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (216.2ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.0ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.0ms)
Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (335.3ms)