So, we’re continuing from here: https://puneetitengineer.wordpress.com/2009/08/12/send-tweets-fr…ls-application/
So far we’ve covered the basics of it, now its time to create some controllers…. Open your command/terminal and fire this command:
ruby script/generate controller twitt
Once you’re done, open this file and write the below code inside it:
class TwittController < ApplicationController
gem(‘twitter4r’, ‘>=0.2.0′)
require ‘twitter’
require ‘twitter_search’
require ‘rubygems’
before_filter :authorize, :except => [:login, :authenticate, :save_users, :twitter_cred]def login
@user = User.new
enddef authenticate
@user = User.new(params[:user])
client = Twitter::Client.new
if client.authenticate?(@user.username, @user.password)
@username = User.save_users(params[:user])
session[:user_id] = @user.id
session[:username] = @user.username
session[:password] = @user.password
redirect_to :action =>’post_status’
else
render :action =>’login’
endend
end
Now, open /app/views/twitt/login.html.erb and paste below lines:
<% form_for :user, :url => { :action => :authenticate } do |form| %>
<%= label :user, :username, “UserName:” %>
<%= form.text_field :username, :size => 30 %><%= label :user, :password, “Password:” %>
<%= form.password_field :password, :size => 30 %><%= submit_tag “login” , :class => “submit” %>
<% end %>