Archive

Posts Tagged ‘rails’

Crop center and resize paperclip image attachment

has_attached_file :profile_image,
storage: :s3,
s3_credentials: {
bucket: Settings.s3_bucket_name,
access_key_id: Settings.aws_access_key_id,
secret_access_key: Settings.aws_secret_access_key
},
default_url: '/assets/default_profile_pic.png',
styles: { square_50: '', square_100: '', square_193: '' },
convert_options: {
square_50: '-gravity center -resize 50x50^ -crop 50x50+0+0',
square_100: '-gravity center -resize 100x100^ -crop 100x100+0+0',
square_193: '-gravity center -resize 193x193^ -crop 193x193+0+0'
}

Categories: Uncategorized Tags: , , ,

sendmail settings in rails 3 application

Open “application.rb” file in “config” folder of your application and add the following data to it.

*************************************************************

config.action_mailer.delivery_method = :sendmail

config.action_mailer.sendmail_settings = {
:location => ‘/usr/sbin/sendmail’,
:arguments => ‘-i -t’
}

config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true

*************************************************************

Categories: Uncategorized Tags: ,

Rails and AJAX Image Upload using jQuery

Hi,

When uploading image in normal method,  getting result after page reload. Its quit not looking good. So tried simple method using jquery,

image upload action look like below in controller

 @image = Image.new(params[:user_avatar])
 @image.save
and
the view page look like,
<% remote_form_for(:user_avatar, :url => { :controller => "users", :action => :avatar_upload }, :html => { :method => :post, :id => 'uploadForm', :multipart => true }) do |f| %>
Upload a file: <%= file_field_tag "user_avatar", :size => 15 %><%= submit_tag 'Upload' %>
<% end %>

and important below script,

$('#uploadForm input').change(function(){
 $(this).parent().ajaxSubmit({
  beforeSubmit: function(a,f,o) {
   o.dataType = 'json';
  },
  complete: function(XMLHttpRequest, textStatus) {
   // For example, if you have an image elemtn with id "user_avatar", then
    
$('#user_avatar').attr('src', XMLHttpRequest.responseText);
  },
 });
});
Categories: Rails Tags: , , ,