Posted in TechSlam.Net
Hi
This blog has been moved to new permanent domain at TechSlam.Net. All further posts will be in this new domain. So see you there. Thanks :)
Welcome to Aslam's Buzz. Here you can find a lot of useful articles related to the latest web technology which I come across being an application developer.
Posted by TechSlam | Comments: (7)
Posted in TechSlam.Net
Hi
This blog has been moved to new permanent domain at TechSlam.Net. All further posts will be in this new domain. So see you there. Thanks :)
It's been a long time since I had any post in my blog. Been quite busy. Yes lot of things happened in the mean time and I need to get back to the track. Rails 3, Wordpress 3 etc. I have to update myself with these and get started again.
Meanwhile I have come across a wonderful learning resource on Rails 3 which I would like to share with everyone. It seems to be quite good to get your feet wet on Rails 3 :
By : Michael Hartl
gem install twitter
ruby script/generate controller twitter_publishNow add the following code to your newly created 'TwitterPublishController'
Controller TwitterPublish < ApplicationController
require 'rubygems'
require 'twitter'
def tweet
httpauth = Twitter::HTTPAuth.new('twitter_username', 'password')
@user = Twitter::Base.new(httpauth)
end
endIn the above controller code, provide the required twitter login details.<% @ user.friends_timeline.each do |tweet| %>
<%= image_tag "#{tweet.user[:profile_image_url]}" %>
<%= tweet.user[:screen_name] %> <br/>
<%= tweet.text %><br/>
<% end %>Now if we run the server, and check out the link http://localhost:3000/twitter_publish/tweets , we will find all the latest tweets from the people I am following will be listed down along with their image.<% form_for :twitter do |t| %> What's happening ? <%= t.text_field :tweet %><br/> <%= t.submit "Tweet" %> <% end %>And to create the update we send as tweet through the text field, we have to add the following code to our tweet method in TwitterpublishController:
if request.post? @user.update(params[:twitter][:tweet]) redirect_to :action=>'tweet' endThat's all, you can now tweet directly from your rails application.
Are you a book lover ? Do you like to share reviews about the books you have read or are you looking for some reviews on certain book you are planing to read ?
RubyConf India 2010 was one great success. Two days of valuable experience. I am a newbie to the Ruby Community. And I must say, this community rocks. With its wings starting to spread over India, it is indeed going to make a deep Impact. This Ruby Conference gave me and my friends an oppurtunity to interact with some of the great programming geeks of the world, like Ola Bini, Obie Fernandez, Nick Seiger, Satish Talim to mention a few. They are a real insipiration to a newbie like me.
Find the Full Post at the new domain of Aslam's Buzz at HERE
So here comes the month of march. You must be thinking what's so special about March and if you have started thinking about the same, well, please do let me know if there is anything special about March. For now, let me get the things straight for this post.
Few months ago(I assume in January 2010), I had written a post on Rails gem called "AuthLogic" for the purpose of user authentication.
Here is the link for that post if you do not know, what is AuthLogic all about.
With the help of AuthLogic, we created a beautiful user registration and login/logout features for a web application. Here, when a user registers, on successful registration he will instantly get logged in. But in most web application, that is not the case, We need the registered user to verify his account before his account is activated, and for that, we need to send a verification email with verification related info to the user. So in this post I will be giving you all the necessary information with codes, on how this feature can be achieved.
Add the following codes to your Model "user_session.rb"
class UserSession < Authlogic::Session::Base
validate :check_if_verified
private
def check_if_verified
errors.add(:base, "You have not yet verified your account") unless attempted_record && attempted_record.verified
end
end class AddVerifiedToUser < ActiveRecord::Migration
def self.up
add_column :users, :verified, :boolean, :default => false
end
def self.down
remove_column :users, :verified
end
end def create
@user = User.new(params[:user])
if @user.save
@user.deliver_user_verification_instructions!
flash[:notice] = "Registration verification email sent.Please verify your account."
redirect_to root_url
else
render :action => "new"
end
end def deliver_user_verification_instructions!
reset_perishable_token!
Notifier.deliver_user_verification_instructions(self)
end def user_verification_instructions(user)
subject 'User verification instructions'
recipients user.email
from 'XYZ Notifications'
sent_on Time.now
@body[:url] = "http://test.domain.com/user_verifications/show/#{user.perishable_token}"
end You have created an account for http://domain.com Please follow the link below to verify your account and get started with XYZ <%= @url %> If the above URL does not work try copying and pasting it into your browser. If you continue to have problem please feel free to contact us.
class UserVerificationsController < ApplicationController
before_filter :load_user_using_perishable_token
def show
if @user
@user.verify!
flash[:notice] = "Thank you for verifying your account. You may now login."
end
redirect_to root_url
end
private
def load_user_using_perishable_token
@user = User.find_using_perishable_token(params[:id])
flash[:notice] = "Unable to find your account." unless @user
end
end def verify!
self.verified = true
self.save
end That is it. On successful verification, the verified field gets a value of one and thus, user will be able to log in. So have you guys tried any other ways of doing this. Please share your ideas with me.
© All Rights Reserved. Aslam'sBuzz
Theme by : Hosting and Cheap Hosting

