0

I'm not sure if its imagemagick or not!

This is in my User.rb, I don't get any errors, Just a blank image! Please let me know how I can fix this!

class User < ActiveRecord::Base
   has_secure_password
   validates :email, :name, presence: true, uniqueness: true 
   validates_inclusion_of :age, in: 10..100
   validates :password, presence: true 
   has_attached_file :profile_picture,
           :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
           :url => "/system/:attachment/:id/:style/:filename", 
           :storage => :fog,
           :styles => { :medium => "300x300>", :thumb => "100x100>" },
           :default_url => "C:\row\website\public\images"

end

This is in my Development.rb,

Rails.application.configure do

  config.cache_classes = false

  config.eager_load = false

  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = false

  config.active_support.deprecation = :log

  config.active_record.migration_error = :page_load

  config.assets.debug = true

  config.assets.digest = true

  config.assets.raise_runtime_errors = true

  Paperclip.options[:command_path] = "C:\ImageMagick"

end

1 Answers1

1

Paper clip for windows 7

If you're using Windows 7+ as a development environment, you may need to install the file.exe application manually. The file spoofing system in Paperclip 4+ relies on this; if you don't have it working, you'll receive Validation failed: Upload file has an extension that does not match its contents. errors.

To manually install, you should perform the following:

Download & install file from this URL To test, you can use the following: untitled

enter image description here

Paperclip is distributed as a gem, which is how it should be used in your app.

Next, you need to integrate with your environment - preferrably through the PATH variable, or by changing your config/environments/development.rb file

PATH

1. Click "Start"
2. On "Computer", right-click and select "Properties"
3. In properties, select "Advanced System Settings"
4. Click the "Environment Variables" button
5. Locate the "PATH" var - at the end, add the path to your newly installed `file.exe` (typically `C:\Program Files (x86)\GnuWin32\bin`)
6. Restart any CMD shells you have open & see if it works

OR

Environment

1. Open `config/environments/development.rb`
2. Add the following line: `Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin'`
3. Restart your Rails server
Either of these methods will give your Rails setup access to the file.exe functionality, this providing the ability to check the contents of a file (fixing the spoofing problem)

Include the gem in your Gemfile:

gem "paperclip", "~> 4.2"

In MODEL

class User < ActiveRecord::Base
     has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png", :path => ":rails_root/public/system/:class/:attachment/:id_partition/:style/:filename" 
  validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/

end

Migration

  class AddAvatarColumnsToUsers < ActiveRecord::Migration
  def self.up
    add_attachment :users, :avatar
  end

  def self.down
    remove_attachment :users, :avatar
  end
end

Views

<%= form_for @user, :url => users_path, :html => { :multipart => true } do |form| %>
  <%= form.file_field :avatar %>
<% end %>

Controller

def create
  @user = User.create( user_params )
end

private

# Use strong_parameters for attribute whitelisting
# Be sure to update your create() and update() controller methods.

def user_params
  params.require(:user).permit(:avatar)
end

Show Views

 <%= image_tag @user.avatar.url %>
<%= image_tag @user.avatar.url(:medium) %>
<%= image_tag @user.avatar.url(:thumb) %>

For FOG

config/environments/*.rb files on config.paperclip_defaults, these will get merged into Paperclip::Attachment.default_options as your Rails app boots. An example:

  module YourApp
  class Application < Rails::Application
    # Other code...

    config.paperclip_defaults = {:storage => :fog, :fog_credentials => {:provider => "Local", :local_root => "#{Rails.root}/public"}, :fog_directory => "", :fog_host => "localhost"}
  end
end

And it will work paper clip in win 7

Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74
  • This has worked wonderfully! The only problem is I had to change the original html code you gave me from <%= form_for @user, :url => users_path, :html => { :multipart => true } do |form| %> I changed it to my original one and it worked <%= form_for (At symbol)user, :html => { :multipart => true } do |f| %> –  Feb 12 '15 at 08:34
  • Only one problem, Where can I put a default image for any new users that doesn't have a profile picture? –  Feb 12 '15 at 09:14
  • if it will same for all users then you can simply use `assets/images` folder to use image – Rajarshi Das Feb 12 '15 at 09:24
  • That's not working at all, I set it to the correct path and still nothing. –  Feb 12 '15 at 09:25
  • in assets? folder did you kept it? – Rajarshi Das Feb 12 '15 at 09:25
  • after putting default image in assets folder set background image in css `background-image:url(<%=asset_path "user_logo.png"%>);` Then `bundle exec rake assets:precompile RAILS_ENV=production` for production – Rajarshi Das Feb 12 '15 at 09:28
  • Why would I need to do all of that? –  Feb 12 '15 at 09:29
  • as this is default image use for all users no need to upload it again – Rajarshi Das Feb 12 '15 at 09:30
  • Invalid CSS after "...und-image: url(": expected ")", was "<%= asset_path ..." –  Feb 12 '15 at 09:38
  • see this below one http://stackoverflow.com/questions/15257555/how-to-reference-images-in-css-within-rails-4 – Rajarshi Das Feb 12 '15 at 09:46