Monday, May 3, 2010

Users

Haven't had much chance to work on this recently, but made some time for the past week or so. I found Authlogic, a premade Rails user package that seems pretty powerful and easy to use. Following some tutorials the site is now capable of simple user registration, login and logout, and profile editing.

Things to work on:
1. User registration validated by email or Captcha
2. Limiting certain site functions (like new site submission?) to logged in users.

I still haven't figured out how to do the FMyLife voting scheme. For those that don't know, fmylife's entries each have a vote up and vote down function. The magic is that you don't need to be logged in or registered to vote, it simply allows you to vote. When you do, the option to vote goes away for that entry. How do they do it?? Some sort of javascript, but what? That's what I'd like U's voting to be.

Monday, March 29, 2010

"Refresh" idea

Using some AJAX or something, how about have the site update every 30 seconds or so, and the links move up or down automagically? It would look cool and people wouldn't have to constantly refresh. Pipe dream for now, so far off.

Minor updates

Brian made a great observation. Presently the site treats votes as a single entity. That is, voting up or down causes the overall votes tally to go up or down. His idea was that there should be a separate count for "vote ups" and "vote downs". This way, there is a measure of total votes, which can indicate general interest in a topic.

I asked Brian and Steven to populate the site so there's a good base for a search to work on. I must say, I enjoy using the site. I find articles I wouldn't have found on my own, some entertaining stuff. Another simple improvement I can make: add Vote Up and Vote Down in the specific category pages. Also, alternating row color changes.

UPDATE:
Removed "num_votes", replaced with "vote_ups" and "vote_downs". Vote up and vote down buttons now work to increment these two values. Had a hell of a time getting such a simple thing to work. Used migrations to add/remove/change the columns, then when I tried to populate vote_downs with default values, it freaked out. Turns out it was because my model had some num_votes usage, and that was screwing everything up. Fixed that, everything is now peachy keen.

check out:
Change values/add defaults during migration:
http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

Interesting way to go through an array of things: array_name.map {|x| do stuff}, maybe sometimes array_name.map!{|x| do stuff}

Sunday, March 28, 2010

Categorizing

I haven't been able to get the search working yet, it's a bit complicated obviously. Instead I added the categorizing functionality. In the main page, the categories are now clickable. The links take you to a new page showing just links of that category. Score is calculated (and used to sort descending as usual). There is a link to go back home.

Moving to MySQL

When I first started this project I wanted to use MySQL as the database: it was already installed on my computer, and in general MySQL enjoys widespread use. I couldn't get it to work, so I went with the default SQLite db, which worked fine.

The next major addition I'd like to make to U is a full text search. After some exploration, I settled on Sphinx. However, it seems Sphinx only supports MySQL and PostgreSQL, and maybe some commercial stuff. I went back to trying to use MySQL. After some installing, uninstalling with apt-get and gem (and remembering my root password), I got it working. We are now on "kepplerapp3".

Now on to getting Sphinx to work.

Thursday, March 18, 2010

Voting

Added voting functionality - super easy! Created two new controller methods, links for each URL. Up and down arrow images added as well (using image_tag), looks decent.

http://snipplr.com/view/5595/rails-link-to-an-image-instead-of-text/

Used GIMP to crop and shrink a stock image for the arrows. Pretty decent, easy to use.

URL validations

Added more robust URL validations. Some manual checking is done, as well as a URI request to read the http header.

http://snippets.dzone.com/posts/show/10225
http://actsasblog.wordpress.com/2006/10/16/url-validation-in-rubyrails/

vim show line numbers => :set number
remove numbers => :set nonumber

Tuesday, March 16, 2010

Hpricot? Here we go again

Steven suggested that the list could benefit by showing more human words, aka the site's title. After cursory attempts to find a quick fix, I remembered Hpricot! What the hell did I do for half my thesis if not read data from websites? Some quick memory refreshing was all I needed:

Install:
sudo gem install hpricot

To use:
require 'rubygems'
require 'hpricot'
require 'open-uri'

doc = Hpricot(open(url, 'User-Agent' => 'whatever'))
doc.search("title").text

I guess User-Agent tells the site what browser I'm using? digg wouldn't work without it. Odd...
http://stackoverflow.com/questions/1386985/timeout-error-with-hpricot-in-rails-controller
"title" looks for the title tag hopefully. Seems to work for now.

Added alternating row colors.
http://blogs.csuchico.edu/ik/2006/04/12/alternating-row-colors-with-ruby-on-rails/
http://paulsturgess.co.uk/articles/show/15-alternate-row-classes-with-ruby-on-rails

Monday, March 15, 2010

Radio buttons

Successfully added radio buttons to replace the drop down list, for choosing categories. Not aligned the way I'd like, but still clean and effective.

Next: Cannot submit without choosing a category - forces all sites to have a category. How would we deal with sites that are already submitted - can we suggest (pre select) the existing category?

Digg seems to be updating themselves - no need to log in, more categories, faster. Sounds like they're copying us! Jerks.

Wednesday, March 10, 2010

Too close, squeezing in?

At times I worry - how similar is this site to Digg and Delicious? Kind of like a middle ground I think. Perhaps I should use those sites more, contribute, get a better feel for them.

Tuesday, March 9, 2010

Category organization idea

class of categories
sports
  • nba
  • nfl
  • mlb
  • mls
  • epl
  • sl
  • nhl
news
  • us
  • world
business
  • stocks
  • gov

# access into category and sub-category will be accomplished by a 2 dimensional index pair
# e.g. (1,4) = sports,mls, (3,1) = business,stocks
end

Novel idea: how about we let the first person who submits an idea control what category it is?
Once its set, its set for life. Might give people incentive to be the first to submit.
Maybe this is a cooky idea. What if they mess up and label incorrectly?

No "news" category?

Sunday, March 7, 2010

Updated hyperlinks, ranking formula, background image!

1. Hyperlinks now update the num_clicks variable. The links also redirect to the named url. One issue I have: I'd like to be able to stay on the current page, open the url in a new window, but I can't figure out how to do that. As it stands, clicking the link will navigate away from the page.

I was able to open a new window if it was just a straight up link (no num_click processing). It might be impossible to do both, we'll see.

2. In the 'index' controller method I had originally sorted the list of url's by number of submissions. It was trivial to update it to use a formula. Basically it is now ranked by the value of: (num_submissions * 10) + (num_clicks * 2) + (num_votes * 5). No way to vote yet though.

3. Found a pretty background image, added it to public/images, inserted a line into the CSS file, bam. The site looks way better for such a simple thing.

How should I implement the Categories? User picked (from drop down), or Steven's original 'keywords' idea?

Saturday, March 6, 2010

incrementing submissions, links, url validation

God, so much grunt work this past week. I think I've made some decent progress though.

1. incrementing submissions - Using form_tag to call a controller method, a preexisting url is incremented
2. Spent WAY too long trying to figure out the link/url showing up on the page properly. For some reason the View would keep adding things to the string I passed it (if it wasn't a "proper" url). After spending days trying to fix it, I decided it would just be easier (and possibly better practice) to validate URLs as they're submitted. Used a model validation.
3. See #2.

UPDATE:
Apparently, http: is a valid URL, as is http:/, http://, http://anything.
This is the info I used: http://mbleigh.com/2009/02/18/quick-tip-rails-url-validation.html

Perhaps there is a better way to do this.

Thursday, January 28, 2010

Models and Default Values

Couple notes:

script/console:
1. reload! - reload all the Rails stuff
2. Model_name.destroy(id_number) - delete an object from a table

Model Validation:
validates_presence_of :url <-- look at spelling of presenCe!!
validates_uniqueness_of :url
See http://juixe.com/techknow/index.php/2006/07/29/rails-model-validators/
also in Model file is Default Values
before_save :default_values
def default_values
if self.column_name == nil
self.column_name = 'hello'
end
nil
end

before_save will let me execute a function before the object gets saved (new or update). I check to see if a value is designated. If not, use the default value.
Use 'nil' at the end to account for strange behavior with a boolean getting set to false. See http://www.neeraj.name/blog/articles/838-before_save-callback-be-careful-accidentally-do-not-return-false

Tuesday, January 26, 2010

To do

1/26
  • Add default values for Site model. There was an error during load of main page, apparently because of nil values. - DONE

Monday, January 25, 2010

Installation

Mainly used instructions from https://help.ubuntu.com/community/RubyOnRails

Some problems with installing and using RubyGems. Followed direction from http://railsforum.com/viewtopic.php?id=34044, which states that I should install from source. Again, ubuntu site had such instructions (wget, tar, etc)

Edit apache config file, /etc/apache2/apache2.conf:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger
-2.2.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.9
PassengerRuby /usr/bin/ruby1.8

Create new file in /etc/apache2/sites-available/larrychang.dyndns.org:

ServerName ror.myhost.com
DocumentRoot /home/myuser/www/mynewapp/public
RailsEnv development


sudo a2enmod rewrite
sudo a2ensite ror.myhost.com
sudo apache2ctl restart

other notes:
http://httpd.apache.org/docs/2.0/vhosts/examples.html#port
file is at /etc/apache2/apache2.conf
/etc/apache2/sites-available