@category = Category.where(:slug => params[:category]).select(:id).first.id if params[:category]
Enough said.
The holidays always seem to creep up on me.
This is the first holiday season I have been at my new gig and we’ve been quite busy busting our asses to get everything in line for next year. So the past few weeks I haven’t had a lot of time to get work done on Type Aloud but that all changed earlier this week.
For the past couple of weeks I have been sitting on the code and focusing on getting the design done. That meant learning a lot of interaction in Rails that I did not know before, working on some CSS beautification and generally cleaning up the god awful standard forms that are generated through the Rails scripts. I decided earlier in the week that I would send out an e-mail to all of my testers and let them know I am planning on pushing a release candidate for their testing.
After some successful UX testing tonight I am going to try to push a new candidate each night for the foreseeable future. My plan is to release to beta on New Years eve flipping the switch on-or-around midnight in a ceremonious occasion which will involve the consumption of a lot of booze. But all that hinges on the UX and integration/functional testing that myself and my testers are going to perform.
Next week the goal is to send out the invite to everyone who has signed up for early access and shut off the form in preparation for the switch. So if you’re a writer, reader or poet and you’re interested in getting involved and helping me out feel free to sign up with your e-mail address. Its free, and I won’t sell them to some clearing house.
Good times are ahead!
After several months of tinkering I have finally, successfully, gotten my hackintosh setup complete with working sound. Last night I got home from Food+Tech Hackathon in SoHo and decided that I was going to make it my mission to get this heap in working order. After about an hour, a shower and some Jameson, the bad mamma jamma was running smooth like butter.
Some other not-so-awesome achievements was finally installing Outlook 2011 on my MacBook after being embarrassed because I was unable to open up a spreadsheet while working on Milk Hack. Which, in and of itself, deserves a little bit of explanation. I decided to go to this food hackathon hosted by the great Danielle Gould and one of the ideas that was proposed was her own: to find get some visualizations in pricing information released by the USDA.
Now most of you that know me can attest that I absolutely hate the process of wrapping my head around statistics, but I love information and data hacking. Luckily enough I was joined by the R guru Drew Conway and what he was able to produce was a sweet animation that we threw up on vimeo. After pouring through several spreadsheets of data I then went to work on what is now the design of http://milkhack.com.
All in all it was a great day spent outside of the cold day in New York City. Big props go out to the Gojee team for hosting the event at their offices. I had a blast, met some great people and ate some amazing food. Who could ask for more?
I have been doing some hacking on Type Aloud and I was looking for an answer to a question that was bugging me: what is the best way to use link_to with a vanity URL setup? I asked my question over at Stack Overflow and I figured I would post the answer to the question here in case anyone was looking as I was.
Inside of my application the route setup is quite simple.
match '/:id', :to => "users#show" match '/:user_id/:id', :to => "stories#display"
Now I want to be able to make a very simple call inside of my view logic which will print out a pretty URL. Since I am using resource definitions for several controllers I cannot use the normal Rails URL helpers. The answer to my question is actually quite simple, and I already have used it before, but what I wasn’t doing was correctly passing through the objects into the helper. Here are the changes that you need to make to those routes above.
match '/:id', :to => "users#show", :as => "vanity_show_user" match '/:user_id/:id', :to => "stories#display", :as => "vanity_show_users_story"
And finally inside of your view you would build both links like the following.
<%= link_to @story.name, vanity_show_users_story_path(@user, @story) %> <%= link_to @user.name, vanity_show_user_path(@user) %>
I hope that this helped you out as much as it helped me! Kudos to the amazing Ryan Bigg for the original answer.
The past couple of weeks I have been doing some research because I am planning on working on a FastCGI Model-View-Controller framework for developing web application services in C++. I am a C++ engineer by day and have been working with the language for nigh on a decade. The brief research I was able to do has shown me that there are no DataMapper or Active Record open source libraries available.
What Exactly Is The N+1 Query Problem?
When using an abstract framework to build a data model for use with an SQL-esque language you generally need to build a set of classes to model the schema in said language. For Type Aloud, lets say that I want to display all of the stories in a set of categories after you get them back based upon two slugs taken from the site’s URL.
SELECT id FROM categories WHERE slug='sci-fi' OR slug='fantasy' SELECT id, name FROM stories WHERE category_id = 0 OR category_id = 1
How many queries will be run? At most there will be two queries, but what about if none of the categories match the two slugs provided? That first dangling select query will be executed each and every time even if there are no matches to search against. How can we fix this?
SELECT * FROM stories INNER JOIN categories ON stories.category_id = categories.id AND (categories.slug = 'sci-fi' OR categories.slug = 'fantasy')
This type of explicit join will allow you to execute a single SQL query and, in the long run, will save you thousands of CPU cycles with your web applications. This type of data mapper already exists in Ruby on Rails using the Data Mapper gem which is freely available. But as of right now there is no such framework available (unless I am mistaken) in C++ which gives you the power and flexibility to build your data models and eat your cake too. My first plan in developing an MVC framework is to work on architecting a proper data mapper library for C++.
Anyone else game?
I decided to take some long needed rest away from the computer and enjoy my Thanksgiving holiday with friends and family. This has put some of my development initiatives on the back burner. I am aiming to gear up this weekend and hopefully be able to release a little tidbit at the end of this weekend just for the special someones who sign up for the service early. The current goal is to have story and chapter submission, viewing and commenting up by the end of this weekend.
I will continue the remaining work and slowly release the bits out to my testers. I expect (and hope) those of you that have signed up are ready and willing to start writing some short stories, and eventually, poems!