Romania on Rails

has_many :info, :through=> Romania

rss

I just had two tough days…

One of our clients needed a monthly newsletter.

After some Google searching the only solutions for email queueing I could find were:

I started testing and reading reviews but none seemed to do the job.

Then I remembered that I’ve already developed a mail queue system for one of my past projects (back when using ASP.NET 2.0). There, the solution was to store in a table the sender, recipient, body and the subject. On RoR mail queue does this but I was still getting a strange error that i couldn`t handle.

Finally… I said “why store the e-mail in a table instead of the arguments and build the mail from those arguments before sending it”. So here are the steps to do it.

Create a model named “QueuedMail“:

#in the migration
create_table :queued_mails do |t|
t.column :mailer , :string
t.column :mailer_method, :string
t.column :args, :text
t.column :priority, :integer, :default=> 0
end

In QueuedMail.rb:

class QueuedMail < ActiveRecord::Base
serialize :args
def self.send
find(:all, :order=> "priority desc, id desc", :limit=>10).each do |mail|
mailer_class = mail.mailer.constantize
mailer_method = ("deliver_" + mail.mailer_method).to_sym
mailer_class.send(mailer_method, mail.arguments)
mail.destroy
end
true
end
def self.add(mailer, method, args, priority)
create(:mailer=>mailer.to_s, :mailer_method=>method.to_s, :args => args, :priority=> priority)
end
end

Now, if you want to send a mail instead of sending with ActionMailer you call QueuedMail.add and it saves the params into the database.

Example:

You have the ActionMailer class named “Mail” and the method “account_created” that recives the params “to”.

Instead of Mail.deliver_account_created(to) you need to code QueuedMail.add(Mail,”account_created”, { :to => “mail@mail.com” }, 0 }

If you have an important email that needs to be sent before others you just set a higher priority.

How to send them?

By using a cron job!
script/runner "DelayedMail.send" -e production

Another reason to love rails !

<%= human_size(File.size("#{RAILS_ROOT}/public/secure/"+c))%>

Where c is a filename.

More info here

I`ve this problem a few times. After inserting or deleting an element the list isn`t sortable anymore :).

To make it sortable again, put this line in the rjs that updates the list:

page.sortable 'photos', :tag => 'div',:overlap=>'horizontal', :constraint=> false, :url => catalog_products_edit_photos_sort_url, :complete => visual_effect(:highlight, 'photos')

And it works!

When i waked up this morning I`ve found from seo-romania.com that Google updated the PR yesterday. Sadly RomaniaOnRails was launched too late and recived 0 :|.

This is how I generate my google sitemap for my sites: :).
1. First, create a controller named xml.
2. Then, for example for the tag links create this method in xml_controller.rb

# in xml_controller.rb
def tags
    @tags = Tag.find(:all, :conditions=> "approved = true")
end

3. In the Views/xml create a tag.rxml file:

# in views/xml/tags.rxhml
xml.instruct! :xml, :version=>"1.0"
    xml.urlset(:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9"){
@tags.each do |tag|
   xml.url{
     xml.loc(tag_url(:tag=>tag))
     xml.priority(0.9)
     xml.changefreq("weekly")
   }
end
}

4. In routes.rb add the route:

#routes.rb
map.tag ‘tag/:tag’, :controller=>"tag", :action=>"view"
map.connect ‘tags.xml’, :controller => "xml", :action => "tags"

5. Type localhost:300x/tags.xml :)

This is the magical code that I use :). I just create a separate method for each model (products, categories, etc).

Xerox Logo

This is the new XEROX logo. I see it something between Xbox and Sony-Ericsson.

Details here

Recently i needed to setup a Ruby on Rails application to run on a subdomain and I wasn`t able to find any exact information. So, after I clear that out I decided to share this simple steps:

1. Add the subdomain from Cpanel. You should have something like “public_html/subdomain”.

2. Follow the steps from here exepting step 5.

3. Login on the ftp and delete the “subdomain” folder from public_html.

4. With SSH link your apliction to the public_html/subdomain:

        cpaneluser@server [~]# cd public_html
        cpaneluser@server [~]# ln –s ../myapp/public subdomain

This will create a folder “subdomain” in public_html and the server points a subdomain to that folder :).

This stepes worked for me on a Site5 reseller account. I suppose that will work everywere.

1. Login with SSH. 2. Make sure you are in /home/username using “pwd”

   cpaneluser@server [~]# pwd
   /home/cpaneluser

3. Generate the rails application with:

 rails myapp

4. Chmod 755 myapp/public

   cd myapp
   chmod 755 public
   cd ..
 

5. Now you need to link the appliction to the domain.

If you want to point the appliction to the root of the domain (ex. www.domain.com):

    mv public_html public_html.back
    ln -s myapp/public public_html

Or if you want to point to folder of the domain (ex. www.domain.com/myfolder)

   cpaneluser@server [~]# cd public_html
   cpaneluser@server [~]# ln –s ../myapp/public myfolder
 

Romania on Rails is powered by WordPress. Provided by NET-TEC SEO, Nachrichten, Webkatalog, Kredit.