Posts

Showing posts with the label srikanth

Sending HTML mail in rails

Hi pals, If all the mails that you send are in HTML format. its simple. Specify this line in environment.rb ActionMailer::Base.default_content_type = "text/html" If only one action has to be in HTML mail, specify 'content_type' in that action. content_type "text/html" example, def signup_notification(recipient) recipients recipient.email_address_with_name subject "New account information" from "system@example.com" content_type "text/html" end cheers, Sri

select box Send Id, display name..

Hi, used this to send the ID in params & display name in the select box. select_tag "user", options_from_collection_for_select(User.all, :id, :name) For adding option & showing selected params, select_tag "user_id", "<option>select one</option>" + options_from_collection_for_select(User.all, :id, :name, params[:user_id].to_i) -- sri.

Rails - select class not applied

Hi, previously my code was like this, I tried much using, html_options, options, but class is not applied for select. <%= f.select 'difficulty', options_for_select({ "Easy" => "1", "Medium" => "3", "Hard" => "5"}, get_difficulty(@tour).to_s), :class =>'input_text' %> Right way to do: <%= select :tour, :difficulty, { "Easy" => "1", "Medium" => "3", "Hard" => "5"}, {:selected=>get_difficulty(@tour).to_s}, :class=>"input_text" %> Now class is applied!!! Any other better way pls tel me,,.</span>

You’re in the middle of a conflicted merge (git)

Problem Trying to update (pull) in git causes the error ‘you’re in the middle of a conflicted merge’. How to resolve a Git Conflict?  Solution NOTE: Take a backup of your code before you do this. This will remove all your changes and revert to master branch!! To be able to get out of this error try the followng: git reset --hard HEAD git fetch origin git reset --hard origin to reset the state, and then you should be able to use git pull as normal. This site helped me when i faced this problem - http://www.42.mach7x.com/2009/11/24/youre-in-the-middle-of-a-conflicted-merge-git/

Getting Local ip Address

require 'socket' def local_ip orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily UDPSocket.open do |s| s.connect '64.233.187.99', 1 s.addr.last end ensure Socket.do_not_reverse_lookup = orig end p= local_ip puts p

Adding data in add column

Adding data in add column class AddPeopleSalary def self.up add_column :people, :salary, :integer Person.reset_column_information Person.find(:all).each do |p| p.update_attribute :salary, SalaryCalculator.compute(p) end end end

Amazon simple Payment in ruby on rails

hi, Amazon is Doing a great job in rails Payments. here is the ruby code for generation of button. require 'base64' require 'openssl' module PayNowWidgetUtils def generate_signed_form(access_key, aws_secret_key, form_params) form_params['accessKey'] = access_key str_to_sign = "" form_params.keys.sort.each { |k| str_to_sign += "#{k}#{form_params[k]}" } digest = OpenSSL::Digest::Digest.new('sha1') hmac = OpenSSL::HMAC.digest(digest, aws_secret_key, str_to_sign) form_params['signature'] = Base64.encode64(hmac).chomp signed_form = STARTFORM form_params.each do |key, value| next unless key and value signed_form += FORMELEM end signed_form += ENDFORM...

Get the list of sundays in a month

require 'date' class Date def self.last_day_of_the_month yyyy, mm d = new yyyy, mm d += 42 # warp into the next month new(d.year, d.month) - 1 # back off one day from first of that month end def self.print_sundays(d1, d2) d1 +=1 while (d1.wday != 0) d1.step(d2, 7) do |date| puts "#{Date::MONTHNAMES[date.mon]} #{date.day}" end end end date = Date.today month = date.strftime("%m").to_i year = date.strftime("%Y").to_i last_date = Date.last_day_of_the_month(year, month) l_date = last_date.strftime("%d").to_i Date.print_sundays(Date::civil(year, month, 1), Date::civil(year, month, l_date))

Jump to the top of a page

Jump to the top of a page http://www.dynamicdrive.com/dynamicindex5/jumptop.htm this will help in making a top link in each page.

Connecting Db in ruby

MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB_NAME = 'localhost', 'root', '', 'artiklz_development' @@dbh = Mysql.real_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB_NAME)

check whether an url is working or not..

1. For domains: ping "domain name" 2. For urls, use the following.. def check_valid_link(link_url) retrycount = 0 begin res = Net::HTTP.get_response(URI.parse(link_url)) if res.code =~ /2|3\d{2}/ return true else return false end rescue Timeout::Error if retrycount retrycount += 1 sleep 3 retry else return false end rescue return false end end

image science requirement

.ruby_inline/Inline_ImageScience_aa58.c:2:23: error: FreeImage .h: No such file or directory getting such an error?? just install freeimage, http://www.urbanpuddle.com/articles/2008/01/22/install-freeimage-imagescience-on-ubuntu-gutsy#comments the above link will guide u in installing.. thanks,

calling JS from form in rails

"report"},{:method => :post, :onSubmit => "return isNumeric(document.getElementById('premium_user'))"})%>

CSV

hi, any work under csv?? here s something interesting which makes ur csv work easier. http://fastercsv.rubyforge.org/ Thanks.