Friday, April 30, 2010

adding feed burner to your site

use this code for use feedburner give the id of the site..

adding twitter of yours to your site

just use this code to your site

db porting task or db table migration

i was want to migrate the table and i have used this query which helpful


INSERT INTO tg_development.content_masters
(
content_text,
title,parent_id
)
(SELECT `fulltext`,title,CASE WHEN jos_content.sectionid=5 THEN 2 ELSE 3 END FROM tegeek_jo151.jos_content)

which have transfered the all data to other database..

Password Encryption through javascript

hii

in my site in admin panel was wanted to do the password encryption of ruby on rails so i got some resources for it and implemented like this,

first my form of login is like this..
  <%= javascript_include_tag('rsa/jsbn', 'rsa/prng4', 'rsa/rng', 'rsa/rsa', 'rsa/base64', :cache => true) %>


 <% form_tag session_path, :id => 'login' do -%>

Please Login

<%= text_field_tag :username, params[:username] %>


<%= password_field_tag :upassword, params[:upassword] %>

<%= hidden_field_tag :password, '' %>

<%= submit_tag 'Log in' %>
<% end -%>
  <%= hidden_field_tag :public_modulus, @public_modulus %>
<%= hidden_field_tag :public_exponent, @public_exponent %>

Two things to note here. First, we are including the four necessary JavaScript libraries on this page only. Second, we use a hidden field to store/commit the password – this field is populate via JavaScript.

and in the controoller :::::::::
 def new
key = OpenSSL::PKey::RSA.new(1024)
@public_modulus = key.public_key.n.to_s(16)
@public_exponent = key.public_key.e.to_s(16)
session[:key] = key.to_pem
end
def create
key = OpenSSL::PKey::RSA.new(session[:key])
password = key.private_decrypt(Base64.decode64(params[:password]))
user = User.authenticate(params[:username], password)
if user
reset_session # reset session after login
session[:user_id] = user.id
flash[:notice] = "Welcome back, #{user.username}"
redirect_to admin_url
else
flash[:error] = 'Invalid username/password entered'
new and render :action => 'new'
end
end


http://iamjosh.wordpress.com/2008/03/18/encrypting-login-password-without-ssl-in-ruby-on-rails/


Saturday, April 10, 2010

Formating date Time in Rails

Formating date Time in Rails

You can format Date field by using strftime function

example :

Time.now()
=> Wed Dec 12 15:48:59 +0530 2007

Time.now().strftime(“%d/%m/%y %H:%M”)
=> “12/12/07 15:50″

Here’s the (shortened) table for strftime.

%a weekday name.
%A weekday name (full).
%b month name.
%B month name (full).
%c date and time (locale)
%d day of month [01,31].
%H hour [00,23].
%I hour [01,12].
%j day of year [001,366].
%m month [01,12].
%M minute [00,59].
%p AM or PM
%S Second [00,61]
%U week of year (Sunday)[00,53].
w weekday [0(Sunday),6].
W week of year (Monday)[00,53].
x date (locale).
%X time (locale).
%y year [00,99].
%Y year [2000].
%Z timezone name.


How does respond_to work in the Rails controllers?

WTF is going on?!?! (aka the rails respond_to block)

respond_to do |format|
format.html
format.xml { render :xml => @mah_blogz }
end

The key thing to understand is that respond_to is a method attached to your controllers superclass: ActionController, and we are passing in as an argument something called a block:

respond_to (BLOCK STARTS HERE) do |format|
format.html
format.xml { render :xml => @mah_blogz }
end (BLOCK ENDS HERE)

WTF is a block?

It’s like the innards of a function. Read this great post by Eli Bendersky.

Digging into Rails source: respond_to (edited for clarity)

def respond_to(&block)
responder = Responder.new(self)
block.call(responder)
responder.respond
end

What’s the “&” prefixing the block argument?

We are passing respond_to a ruby block. That block is converted to a Proc due to the “&” prefix to the block argument. The functionality of this prefixed “&” is a Ruby feature. Procs are callable, anonymous functions.

So what’s with the |format| stuff back in the controller?

|format| defines that the block takes one argument (referred to inside the block as ‘format’).

This means that inside the respond_to method, we end up with a Proc that takes one argument. This argument has the .xml and .html methods called on it. What do we pass into the Proc as an argument when we call it from inside respond_to? We pass in an instance of the Responder class.

So we end up calling .html and .xml on an instance of the responder class as it is passed into the block (that’s been converted to a Proc) inside the respond_to method… Phew.

So here we are

I’ll leave you to dig further, but basically from here the Responder instance handles .html and .xml via method_missing, depending on mime types your rails app can process. This allows you to configure other mime types from your rails app by registering them in your initialisers.

Sunday, April 4, 2010

Rss Feed

RSS (most commonly expanded as "Really Simple Syndication") is a family of web feed formats used to publish frequently updated works—such as blog entries, news headlines, audio, and video—in a standardized format.