I'm trying to implement a method whereby a user can manipulate three radio buttons, each with assigned methods, to sort the tweets either by retweets, by favourites or default(by date).
Currently, the page lists the tweets by date as default but every time I pressed either of the two buttons, I get the error "This page does not exist."
My .rb file is:
require 'sinatra'
require 'twitter'
require 'erb'
include ERB::Util
config = {
:consumer_key => '..' ,
:consumer_secret => '..' ,
:access_token => '..' ,
:access_token_secret => '..'
}
client = Twitter::REST::Client.new(config)
get '/list_of_tweets' do
puts "Visiting history page..."
tweets = client.user_timeline(user)
@history = tweets.take(20)
erb :tweets_list
end
My tweets_list.erb file is:
<!DOCTYPE html>
<html>
<head>
<title>Twitter Interface</title>
</head>
<body>
<h1>List of Tweets</h1>
<form method="post">
<h3>Sort Tweets by</h3>
<input type="radio" name="operation" value="favorite_count" checked/>Favourites
<input type="radio" name="operation" value="retweet_count"/>Retweets
<input type="radio" name="operation" value="default"/>Default
<input type="submit" value="submit"/>
</form>
<% unless @history.nil? %>
<% if @params[:operation] == "favourite_count"%>
<% @history = tweets.take(20).sort_by!{|tweet| tweet.favorite_count} %>
<% else %>
<% @history.reverse! %>
<% end %>
<% if @params[:operation] == "retweet_count" %>
<% @history = tweets.take(20).sort_by!{|tweet| tweet.favorite_count} %>
<% else %>
<% @history.reverse! %>
<% end %>
<% if @params[:operation] == "default" %>
<% @history = tweets.take(20) %>
<% else %>
<% @history.reverse! %>
<% end %>
<table border="1">
<tr>
<th>Time Posted</th>
<th>Description of Tweets</th>
<th>Number of Retweets</th>
<th>Number of Favourites</th>
</tr>
<% @history.each do |tweet| %>
<tr>
<td><%= tweet.created_at %></td>
<td><%= tweet.text %></td>
<td><%= tweet.retweet_count %></td>
<td><%= tweet.favorite_count %> </td>
</tr>
<% end %>
</table>
<% end %>