RSS Feed Subscribe to RSS

Convert Line Breaks in Rails

This may not be news to anyone else, but it was a surprise to me when I ran into it, so I thought perhaps someone else might find it helpful. Let’s imagine that you’ve got a form with a textarea that allows for a decent amount of user input, like, say a blog post or a news item on your family website.

When you push the “Enter” key it goes down to the next line. Behind the scenes, this is stored in your database as a new line character which is represented by “\n”. The problem is that “\n” has no meaning to a web browser. In web browser language, what you really need is a line break represented by the “<br />” tag. So how do you get all your new lines to turn into line breaks? The answer is one simple method added to your application_helper.rb file in your Rails project.

def line_break(string)
    string.gsub("\n", '<br/>')
end

Then in your view, you simply call the line_break method around the appropriate block of text

<%= line_break(@news.body) %>

and that’s all there is to it!

Apple Turns the Cell Phone Industry Upside-Down?

I read a few articles today that got me thinking. I’ll reference them up front since the ideas I pulled from them are a little intermingled. The first article was How Apple Could Rock Wireless on CNN. The other was on MacRumors called Cingular/Rogers Not Subsidizing iPhone Cost.

I realize it’s unusual to have two articles, but it took both articles to paint the whole picture. Currently, cellular service providers subsidize a large portion (if not all) of the initial cost of a cell phone when their subscribers signs a 1-2 year contract. Cell phone manufacturer’s don’t like this practice because it devalues the phone itself. Rogers will be the sole provider of iPhone service in Canada and reportedly they aren’t allowed to subsidize the cost of the phone.

When Apple announced the $499 and $599 price tags for the iPhone models, many assumed that this was the subsidized price, but given this new news (and the rumors that Cingular is drastically reducing the cost of service) it begins to paint an interesting picture. Apple consumers are typically willing to pay a premium. That being said, if Cingular subsidized hundreds of dollars on the prices on iPhones, it creates an interesting situation where an iPhone and an iPod Nano cost about the same although the devices clearly are not equal.

So what does all this mean? It means that Apple could potentially flip the cell phone industry upside-down. It possibly provides leverage where the cell phone manufacturers can gain a bit more power in the industry and gain a little more control over where things are going. Granted, this is speculative, but the possibility is there. If Apple can convince consumers to pay a premium for their cell phones, then potentially even competitors like Samsung, Sony Ericson, Nokia, LG, and others may even be rooting for the success of the iPhone.

Web Traffic Analysis

In the realm of analyzing traffic that your web-site is generating, there are two main approaches. Log-file analysis & real-time analysis (I don’t know if that’s an industry term, but that’s what I’m going to call it).

Real-Time Analysis
As a general rule, the real-time analysis tools use javascript to track visitors to your website. Pasting a bit of javascript into the header of your HTML pages (or templates) means that every time a page is loaded, your website will send a call to a remote database somewhere with information about the visitor. Logging into the account you’ve created at the remote site will allow you to view statistics with varying levels of details depending on the service. Due to the use of Javascript to track and record statistics, these are completely platform independent.

  • Omniture’s Site Catalyst - Enterprise level analytics. As far as I know, Site Catalyst is really the only player at this level in the market. I don’t know a whole lot about it, but as I get access to it later on, I’m sure I’ll be writing more about it.
  • Google Analytics - As far as I know, this is the weapon of choice for those that don’t have the resources to implement and use site-catalyst but still want real-time analysis of their web traffic
  • Microsoft’s Gatineau - As of this writing, Gatineau isn’t live yet, so we don’t exactly know how it will work, but you can bet their trying to enter the Google Analytics market. Details are sparse, but there are a few details over at searchenginejournal.com
  • Others - There are many other tools available. Some of the ones I know of are Sitetracker, OneStat (pay service), and StatCounter

Log-file Analysis
The alternate method of tracking visitors to your site is to use log-file analysis. Every time your HTTP server sends out a page to a web browser, the request is stored in a log file. A log file is simply a text file on your server that contains IP addresses, times, pages requested, and any other number of statistics. Parsing through the log files and comparing certain bits of data to others allows a detailed picture of the traffic on your website. Because these tools actually live on the servers andlook through log files, they are OS dependent.

  • AWStats - As far as I know, AWStats is the major player in this market. It’s an open-source tool that has been around since before I was doing web development. I don’t have extensive experience with AWStats, but my understanding is that the level of detail is not quite on par with Google Analytics. AWStats works by running a PERL (maybe Python) script that parses through your server log files to generate static HTML pages. A cron job runs the script whenever you schedule it, and then the stats are available at http://yourdomain/stats. There is also a CGI interface that will do it in real-time for you.
  • Others - There are many tools that do this type of job. See the Wikipedia for more options in this arena.

A post from Jimmy Zimmerman highlights one issue with log-file analysis. Blogs and other types of web-sites that encourage user feedback have forms for posting comments, etc. These comment forms are highly targeted by comment spammers that use this method of feedback for free advertising. Since these spams consist of valid Request/Response pairs, they pollute your log files with false data. If you use log-file analysis to track statistics on your site, be aware of this and take steps to cleanse your logs to produce accurate stats.

Search Engine Optimization

Had an interesting discussion in class about search engine optimization in class today. For those who don’t know, search engine optimization is the idea of getting your site to pop up in search engines when certain keywords are typed. Every search engine has different algorithms for determining which links are displayed for certain searches. These algorithms are usually (if not always) secret and constantly evolving to get around the click fraudsters and google bombers.

First let’s talk about how to get your site to show up. There are a few things you can do. I don’t claim to have any special knowledge about any of the search algorithms and the ideas below are not listed in order, they are just some ideas to get you started. I know I’ve started.

  1. Use Google Sitemaps - There are a lot of useful tools at the Google webmaster’s site. In particular, the sitemaps feature allows you to create an xml file that allows you to define links and content in your site. You can even use the Google Sitemap Generator to get it in the proper format, then upload it to the root directory of your server. When Google’s spider comes around again, it gets better information about your site.
  2. Pick a few keywords that you want people to use to find your site. Put them in the Title, the header, the meta tags, and anywhere else you can get them. Certain types of tags are weighted heavier than others, the URL is particularly high =)
  3. RSS Feeds - You can use the Google Webmaster tools and submit RSS feeds to google so it can update the content from your site.
  4. Get people to link to you, if high ranked sites link to your site, this is good for you. A useful tool for this kind of thing is WhoLinks2Me. You can also do a Google search for “link:yoursite.com”.

There Are Limits
Now the caveat at the end to warn you about abusing these methods, particularly #2. One example of the abuse is Googlebombing. Googlebombing refers to the practice of many people all over the web linking the same word to the same site. Google recently changed their search algorithm to “defuse” the bombs, but for awhile, if you googled the word “failure” you’re top hit was President George W. Bush’s website. This has been fixed, but if you search for “utter failure” your top link is an article about Pres. Bush.

Click Fraud
Google also has a feature that allows you to bid on keywords that will link to your site. The hotter the topic, the more expensive the keywords are. You can set limits on how much you want to spend etc. There are also pay-per-click services. I don’t know anything about the details of how these work but I do know that they are available. Click fraud refers to any of a number of practices designed to push your pages higher in Google’s search results.

So the short story is that you walk a fine line with search engine optimization. Get your site to show up on Google, but don’t abuse the privilege.

The Indecisive Platformer

So I’ve now switched back to Wordpress. I just finished a manual migration of sorts to pull all my posts back over from Typo. Part of the problem was mod_ruby woes, part was little bugs, and part was features that just weren’t available (although the skins are way better). Excuse me while the dust settles and I pick up my Wordpress habits once again.

My web-host uses Apache1.3_mod_ruby to host Rails applications. This reloads the entire ruby environment with each page (I’ve been told) and was effecting speed. In addition to that, sometimes, you just got a nice Application Error page that was fixed by simply reloading the page. Not good for PR.

I couldn’t seem to get the Typo trackback feature to work either. It worked fine running on my laptop while I was giving it a test drive, but once it was up in production on the server, it wouldn’t post or receive trackbacks. I decided to chalk this up to weird apache1.3 issues as well, since it seemed to work fine with Mongrel and Lighty.

And finally, there is much more support for multiple users and levels of user access in Wordpress. This isn’t a big issue now, but might become one later on down the road. So to wrap up, I’ve switched platforms once again. I still plan on posting an in-depth review of everything I learned about Wordpress, Typo, and Mephisto when I get some time, but for now, school is keeping me busy.