lundi 15 août 2016

Missing PaperClip Image

Controller File 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

Model File 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

ErrorLog 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:inblock 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:incall' actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.2.6) lib/rails/rack/logger.rb:38:incall_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:inblock 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:intagged' railties (4.2.6) lib/rails/rack/logger.rb:20:in call' actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:incall' rack (1.6.4) lib/rack/methodoverride.rb:22:in call' rack (1.6.4) lib/rack/runtime.rb:18:incall' 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:incall' actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in call' rack (1.6.4) lib/rack/sendfile.rb:113:incall' railties (4.2.6) lib/rails/engine.rb:518:in call' railties (4.2.6) lib/rails/application.rb:165:incall' rack (1.6.4) lib/rack/lock.rb:17:in call' rack (1.6.4) lib/rack/content_length.rb:15:incall' rack (1.6.4) lib/rack/handler/webrick.rb:88:in service' C:/Ruby21-x64/lib/ruby/2.1.0/webrick/httpserver.rb:138:inservice' 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:inblock 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)

Aucun commentaire:

Enregistrer un commentaire