Saturday, March 21, 2009

UPLOADING IMAGES WITH ATTACHMENT FU PLUGIN

step:1

install attachment_fu plugin
rails_app>
script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/

step:2

install minimagick gem

rails_app>gem install minimagick(which is better in memory occuping from rest of it)

step:3
create a controller medias_controller.rb

def index
@medias = Media.find(:all)
end


def new
@media=Media.new
end

def create
@media = Media.new(params[:media])
if @media.save
flash[:notice] = "image successfully uploaded"
redirect_to :action => 'show'
else
logger.debug"%%%%%%%%%%%%% inside else"
flash[:notice]="image not uploaded"
redirect_to :action =>'show'
end
end



def show
@media = Media.find(params[:id])
end


def delete
@media = Media.find(params[:id])
@media.destroy
redirect_to :action =>'index'
end


step:4

in media.rb file

has_attachment :content_type => :image,
:storage => :file_system,
:min_size => 0,
:max_size => 1.megabytes,
:resize_to => '34x38',
:thumbnails => { :thumb => '15x15>' },
:processor => 'MiniMagick',
:path_prefix => "public/medias/"

validates_as_attachment

step:5

In views

views/medias/index.rhtml


<% for media in @medias %>
<%= link_to image_tag(media.public_filename(:thumb)),media.public_filename %>
<%= link_to 'Remove',{:action=> 'delete',:id => media.id},:confirm=> "Are you sure?" , :method => :post %>
<% end %>


views/medias/new.rhtml


<% form_for(:media,:url => {:action => :create }, :html => {:multipart => true }) do |f| %>

Select a photo to upload

Photo: <%= f.file_field 'uploaded_data' %>
<%= submit_tag 'Upload Photo' %>


views/medias/show.rhtml


<%= image_tag(@media.public_filename) %>

ACTION MAILER IN RAILS 2.0

STEP:1

In environment.rb file write it down like this at the end of the file

require 'smtp_tls'
ActionMailer::Base.default_content_type = "text/html"
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :login,(ur authentication method name here)
:user_name => "your gmail id ",
:password => "your gmail password ",
}

STEP:2

Include smtp_tls.rb file in lib folder

STEP:3

Follow this url then for
action mailerto work but dont change any configuration files as mentioned in the url for u