There’s this article on Wired News called Wanted: Free iPod. Will Pay which discusses how people are willing to pay cash in order to obtain freebies, such as iPods and laptops. The article was a real eye-opener for me; I never knew there was an active community of bargain hunters who would actually pay other people to become their “referrals” for things like this, but I guess it does make some sense. If you’re able to get an iPod for $150 rather than $300, then perhaps the savings are worth seeking out and paying complete strangers to sign up for the required services for you.
We’ve all seen ads for places like Free iPods.com while browsing the Web, and while I’ll admit, I’ve thought about signing up to get a free iPod through them, I’d never actually do it. Who’s to say that I’d ever con convince my friends into helping me out to get one. Or, say I did manage to “refer” 5 people, who’s to say that the company would even send me my iPod.
Anyway, in the article, it mentions how people often lose money by paying strangers who never end up keeping their side of the bargain. Business idea: Set up a website where freebie hunters can find other freebie hunters and exchange referrals. It could be set up so that users auction off their time and services eBay-style and the little money involved could be stored away in escrow (ie., the business’ Paypal account) until both sides fulfill their promises. The website proprietors, no doubt, would take a small middleman “tax” for themselves. Of course, I have no idea how legal this idea is, or how financially feasible it is. It’s just an idea. : )
I found the old HTML version of Programming Ruby: The Pragmatic Programmer’s Guide the other day, while searching Google for solutions to a Ruby syntax problem I was dealing with. It’s now bookmarked for later reference, just as the other links included in this post are. (The newer version is also available.)
A little Googling later, I came across RailsFAQ.org, which lists solutions to a number of common problems that Ruby on Rails newcomers face.
One of the links was to Hieraki, which is a web application developed using Ruby on Rails. The website is powered by Trac, which is an “enhanced wiki and issue tracking system for software development projects.” It allows you to navigate Hieraki and view the source code for its files. So, I’ve found myself glancing at the Hieraki source code every so often to see how its authors implemented features that I’d like to implement mine, just to see if I’m on the right track.
I’m in the process of writing my first web service in C# and through the whole process I’ve been surprised at how easy it’s been. It’s generally been the same as any sort of project, except for how it’s intially created and how it’s tested. I’m also in the process of writing my first Windows service in C# that will consume the web service, and, if possible, I’ve been even more surprised at how easy it’s been. Visual Studio.NET _really_ makes it easy to develop these kinds of projects, and I’m becoming more and more of a fan.
If you are interested in developing your own Windows service, take a look at this tutorial on CodeProject. I basically followed this tutorial from top to bottom to set up the basis of the Windows service, which includes an installer that wraps the actual Windows service.
With all this time dedicated to .NET recently, I know I’ve been neglecting my time with Ruby. But, it’s only temporary. I’m still thinking about my Ruby on Rails lyrics project all the time, and when I do get back to developing it, I hope to get a large chunk done.
Note: I have been meaning to re-write this post to make better use of Ruby on Rails helpers, etc. When I first wrote this I was extremely new to Rails and my unfamiliarity with the framework showsUntil I have the free time to re-write this post, please bear with what is currently here and leave comments to help others that follow after you.
Finally! I’ve been working on this little bit of Ruby code for hours now, all because of some odd bugs (which, when I learn Ruby better, will probably cease to become odd) and a lack of good Ruby on Rails documentation.
What I’ve been working on is getting two related HTML drop-down lists to update properly using the built-in Ajax support in Ruby on Rails. Specifically, when the user selects an Artist from the first drop-down list, only that artist’s Albums should be listed in the second. I wanted to do this without having to retrieve all of the albums during the initial page load and without having to do a post back when the user selects an artist. So, that’s where Ajax comes in. Ajax uses the JavaScript XMLHTTPRequest routine to retrieve new data from the server without requiring the user to refresh the webpage.
Some gotchas for the new Ruby programmer / web developer:
- You cannot modify the InnerHTML of a select drop-down list. Instead, you have to modify the InnerHTML of the div that _contains_ the select drop-down list, and when you do you have to recreate the whole drop-down.
- When you are using instance variables (those that begin with the @-sign), ensure that the instance variable exists before trying to use:
@variable += “value”
syntax or else Ruby will throw up an error. For example, before that statement, add a line that reads:
@variable = “” - When concatenating strings that contain instance variables, Ruby is picky in a way that I can’t fully describe. For example, the following does not work:
@html += “<option value=’” + @album.id + “‘>” + @album.album_name + “</option>”
But this does work:
@html += “<option value=’#{@album.id}’>#{@album.album_name}</option>”
Anyway, this is the troubled code that _did not_ work:
admin_controller.rb
@albums = Album.find_all_by_artist_id(@params["artist_id"])
@html = "<select id='album_id' name='album_id'>"
@html += "<option value=''>No Album</option>"
@albums.each do |@album|
@html += "<option value='" + @album.id + "'>" + @album.album_name + "</option>"
end
@html += "</select>"
After hours I got it working with this code:
admin_controller.rb
@albums = Album.find_all_by_artist_id(@params["artist_id"])
@html = "<select id='album_id' name='album_id'>"
@html += "<option value=''>No Album</option>"
@albums.each do |@album|
@html += "<option value='#{@album.id}'>#{@album.album_name}</option>"
end
@html += "</select>"
But, this has to be coupled with the RHTML code in the template, as follows.
add_song.rhtml
<%= javascript_include_tag "prototype" %>
Artist
<select name="new_song[artist_id]" id="new_song[artist_id]">
<option value="">Select Artist</option>
<% @artists.each do |artist| %>
<option value="<%= artist.id %>">
<%= artist.first_name %> <%= artist.last_name %>
</option>
<% end %>
</select>
Album
<div id="album_id_container">
<select name="new_song[album_id]" disabled="disabled">
<option value="">No Album</option>
</select>
</div>
<%= observe_field("new_song[artist_id]",
:frequency => 0.25,
:update => "album_id_container",
:url => { :action => :add_song_artist },
:with => "'artist_id='+value") %>
I’m just beginning to transition to ASP.NET and C# from a largely Java / C++ / C background, and along the way, I’m finding myself often stumped with what seems like really simple problems.
For example, today, when writing a ASP.NET web service in C#, I had trouble casting a money value retrieved from a MSSQL database to a double. The following code would always report an error:
C#
double cost;
cost = (double) dr["cost"];
I also tried using a float, but that didn’t fix the problem either.
The _correct_ type to use in this case is actually Decimal, and I learned this only after a co-worker sent me a link to a document on the MSDN site that has a table showing all of the proper type conversions from one system to another. So, this code _does_ work:
C#
Decimal cost;
cost = (Decimal) dr["cost"];
You can find the table here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingparameterswithdataadapters.asp
(Scroll about halfway down; you can’t miss it.)
19
Models with Associations
Since each song belong to an artist (or multiple artists, depending on how complicated you want to make things), when adding a new song to the database, you want to be able to select the artist from a drop-down list.
In my admin controller, I’ve set up the following:
admin_controller.rb
def add_song
@artists = Artist.find_all
end
This gets me a list of all the artists in the database and stores them in @artists.
Now, in my template then, I can add the following code (adapted from some Recipe example I came across online):
add_song.rhtml
<select name="new_song[artist_id]">
<% @artists.each do |artist| %>
<option value="<%= artist.id %>">
<%= artist.first_name %> <%= artist.last_name %>
</option>
<% end %>
</select>
This will display all of the artists in a drop-down box. Then, when the form is submitted, the id of the artist that is selected (as well as any other fields that you set up) will be accessible through @params["new_song"].
Since each song also belongs to an album, I’d like to have the ability for the user to also select what album the song belongs to when adding the song. Ideally, when an artist is selected, only the albums belonging to that artist would appear in the albums drop-down. To avoid using JavaScript to limit which albums appear, I feel that the form will have to post back to the server in order to accomplish this. So, my next step in getting this lyrics web app going is to figure that out.
19
This WordPress Software
This is the first time that I’ve had the chance to use WordPress, and so far, I’ve been very impressed.
Not only was it easy to install (perhaps because I did it through the CPanel plug-in called Fantastico) but its easy to use, as well. Installing this theme was really straight forward and adding and modifying posts is easy, too.
In the past I’ve played with b2evolution and MovableType, but I was not completely happy with either. Modifying b2evolution to match the look-and-feel of a current site was somewhat difficult and even after I was done, I wasn’t happy with what I had done. With MovableType, I was disappointed with the actual process of posting new content. Perhaps if I had read a tutorial or two, I would have understood the process, but I hadn’t so I didn’t. In any case, I like WordPress a lot more than I did those other two.
19
Setting Up Associations
As my first project with RoR, I’m creating a lyrics website. Thus, there are basically three main models that will have to be maintained through the site: artists, albums, and songs.
So, I’m current in the process of setting up associations between the model classes (Artist, Album, Song) so that I can easily access the associated information. I have no idea if what I’m doing currently is correct, but I’ll probably find out tomorrow when I continue working.
This is what I’ve put into each of the model files so far:
artist.rb
class Artist < ActiveRecord::Base
has_many :songs, :order => "song_name", :dependent => true
has_many :albums, :order => "album_name", :dependent => true
end
album.rb
class Album < ActiveRecord::Base
belongs_to :artist
has_many :songs, :order => "song_title", :dependent => true
end
song.rb
class Song < ActiveRecord::Base
belongs_to :artist
belongs_to :album
end
I have designed the database so that songs do not necessary have to belong to an album, in the case that the album name is not readily available. That's why there's a little bit of redundancy of information.
But, other than that, are any errors apparent to anyone?
19
Late night with Ruby
So I was up til 4am last night with Ruby. I guess I assumed that I’d pick up the language a little easier than I have. Or perhaps I should have just been a little less adventurous and have taken a look at some of the tutorials before jumping into Ruby on Rails head-first.
The first thing I wanted to do with my first project was set up a user authentication system so that I could restrict the creation, modification, and deletion of items to authorized users. Although the Ruby on Rails website has many, many, many different generators that can help people like me get this going quickly, I got completely and utterly confused when doing so. So, after many false starts (during which I tried experimenting with every user authentication generator that the website offered) I took a Counter-Strike break.
After a couple hours of fragging I came back to the project to give it one last go. I settled on just using the simplest generator, Login Generator, and got that working actually quite quickly and easily. I figure I’ll just end up extending this simple user authentication system when I have a better handle on Ruby and Rails. In any case, by 4am when I decided to finally get some sleep, I had gotten the administration area password-protected and had begun playing with adding methods to maintain the various items that my project uses.
So, that’s how my first night with Ruby ended.
When installing the Ruby on Rails framework, I actually found the instructions provided on the Rails site to be a little confusing. To me, it seemed like if I wanted to run the WEBrick web server instead of Apache, that I’d have to find and install the WEBrick webserver myself. But this isn’t the case.
If you are planning on developing on your own computer but are deploying your web application to a host such as TextDrive, then you don’t need to separately download any webserver. What I found out after I had installed Ruby and the Ruby on Rails framework is that the WEBrick webserver had been bundled with Rails and was automatically installed for me. Awesome.
Anyway, if you are looking at installing Rails on Windows, all you need are two files: the Ruby for Windows installation file and the Ruby gems zip file. After you have downloaded both files, you can follow Rails for Windows, lesson 1 to get those both installed and running. You may also want to look at the other lessons if you need to install MySQL or the other tools, but I haven’t (yet) since I already had MySQL installed locally.
Recommended Services
Recent Posts
- Fantastic new corporate themes for WordPress
- Vistaprint offers FREE t-shirts, too!
- 80+ “Your Ad Here” 125 x 125 banners
- 5 Minute Long Tail SEO Drill: More Traffic, Better SERPs
- iPhone and iPod Touch app statistics: OS adoption, purchasing rates
Recent Comments
- malickakor on How To: Cloak your Affiliate Links for Free in Under 3 Seconds
- Neerav on Using JavaScript to validate one or more grouped checkboxes
- Jacob on Using JavaScript to validate one or more grouped checkboxes
- kaify on Using JavaScript to validate one or more grouped checkboxes
- JC Goldenstein on How To: Cloak your Affiliate Links for Free in Under 3 Seconds
Categories
- .net
- acoustic guitar
- affiliate marketing
- ajax
- amazon associates
- blogging
- books
- business ideas
- c#
- code igniter
- dealdotcom
- google adsense
- google adwords
- internet marketing
- iPhone
- javascript
- leadership
- make money online
- mortgage goal
- msn adcenter
- networking
- personal development
- php
- ppc
- ruby
- ruby on rails
- seo
- text-link-ads
- web development
- yahoo search marketing


