Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Voloshin Ruslan http://rubyclub.com.ua/

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

rake task for restart rails application runed on mod_rails


amespace :passenger do
  desc "Restart Application"
  task :restart do
    puts `touch tmp/restart.txt`
  end
end

create new rails rake task

Create new task for /unit/helpers/*_test.rb

Rakefile
namespace :test do
  Rake::TestTask.new(:helpers) do |t|
    t.libs << "test"
    t.pattern = 'test/unit/helper/*_test.rb'
    t.verbose = true
  end

  Rake::Task['test:helpers'].invoke
end

Customize error_messages_for

// description of your code here

 module ActionView::Helpers::ActiveRecordHelper
   def error_messages_for(object_name, options = {})
    options = options.symbolize_keys
    object = instance_variable_get("@#{object_name}")
    if object && !object.errors.empty?
      content_tag("div",
      content_tag(
      options[:header_tag] || "h2",
      "Возникло #{object.errors.count} ошибок при сохранении"
      ) +
      content_tag("p", "Проблеммы возникли для следующих полей:") +
      content_tag("dl", object.errors.full_messages.collect { |msg| content_tag("dt", msg) }),
      "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
      )
    else
      ""
    end
  end
 end
  

Pinging site

Вот простой пример как пропинговывать сайты при новых постах без включения допоплнительных плагинов и модулей

irb(main):032:0>
irb(main):033:0* server = XMLRPC::Client.new("blogsearch.google.com", "/ping/RPC2", 80)
=> #<XMLRPC::Client:0x2aaaaeb222e8 @create=nil, @port=80, @http=#<Net::HTTP blogsearch.google.com:80 open=false>, @proxy_host=nil, @http_last_response=nil, @parser=nil, @timeout=30, @path="/ping/RPC2", @password=nil, @http_header_extra=nil, @use_ssl=false, @host="blogsearch.google.com", @user=nil, @proxy_port=nil, @auth=nil, @cookie=nil>
irb(main):034:0> server.call("weblogUpdates.extendedPing", 'Rubyclub.com.ua new on site','http://rubyclub.com.ua/', 'http://rubyclub.com.ua/messages/rss')
=> {"message"=>"Thanks for the ping.", "flerror"=>false}

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS