Posts

Showing posts with the label ruby on rails

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.

Table Sorting Jquery Plugin

Hi, I was wondering how to sort a table. I got this plugin & did it in 10 mins. Here is an useful plugin in jquery, Reference URL : http://tablesorter.com/docs/#Download Table sorting is pretty much easier using this tablesorter plugin. Thanks, Srikanth

MySQL Change root Password

Image
Source : http://www.cyberciti.biz/faq/mysql-change-root-password/ mysqladmin command to change root password If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows: $ mysqladmin -u root password NEWPASSWORD However, if you want to change (or update) a root password, then you need to use following command $ mysqladmin -u root -p'oldpassword' password newpass For example, If old password is abc, and set new password to 123456, enter: $ mysqladmin -u root -p'abc' password '123456' Change MySQL password for other user To change a normal user password you need to type (let us assume you would like to change password for vivek): $ mysqladmin -u vivek -p oldpassword password newpass Changing MySQL root user password using MySQL sql command This is another method. MySQL stores username and passwords in user t...

Polymorphic Association

Reference : http://charlesmaxwood.com/ruby-on-rails-restful-links-when-you-dont-know-the-class/ Example : restful routes: map.resources :users map.resources :groups Model Relation: class Post < ActiveRecord::Base belongs_to :owner , :polymorphic => true end class User < ActiveRecord::Base has_many :posts , :as => :owner end class Group has_many :posts , :as => :owner end Now, let’s say that when you show a post, you want to provide a link to the owner of the post when you display it on its show page. You know that because you’ve provided the restful routes in your config/routes.rb file as show above, you get the nice functionality of the user_path and the group_path methods. The problem is that because you don’t know if @post.owner is a user or a group. Documentation : http://railsbrain.com/api/rails-2.3.2/doc/index.html?a=M000261&name=polymorphic_path Thanks, Srikanth

string conversions

>>> print "Before %s After" % 7 Before 7 After >>> print "Before %x After" % 15 Before f After >>> print "Foo %04d Bar" % 3*3 Foo 0009 Bar

jquery show, hide

http://docs.jquery.com/Downloading_jQuery#Current_Release current version of jquery can be downloaded here.

Check Whether a test Credit Card is working.,

require 'rubygems' require 'active_merchant' # Use the TrustCommerce test servers ActiveMerchant::Billing::Base.mode = :test # ActiveMerchant accepts all amounts as Integer values in cents # $10.00 amount = 1000 # The card verification value is also known as CVV2, CVC2, or CID credit_card = ActiveMerchant::Billing::CreditCard.new( :first_name => 'Bob', :last_name => 'Bobsen', :number => '349298720353895', :month => '8', :year => '2012', :verification_value => '1234' ) puts credit_card.valid?

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...