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
Tuesday, March 16, 2010
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.
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
# 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?
sports
- nba
- nfl
- mlb
- mls
- epl
- sl
- nhl
- us
- world
- 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?
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.
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
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
Subscribe to:
Posts (Atom)