Mae West via farm1.static.flickr.com
New, awesome Shaun of the Dead photos w/@simonpegg, @nickjfrost and @edgarwright! Via @totalfilm, where they have more pics!
They Might Be Giants - Put It to the Test (via ParticleMen)
The Blob 1958 opening tune (via bubbazametti)
In my new app I have a whole bunch of nested models. For the most part they all have the same database structure and can use very similar partials. I hate to repeat code because it usually makes my life more difficult when I need to go back and change something or do maintenance. I am now placing these partials in a single location that all of these models have access to.
Problem is I had a very difficult time telling the partials what object it needed to represent without adding a parameter. (I am making a lot of AJAX calls) I solved it by using the controller that was passed along with the request. After that I needed to take that string that was passed and transform it so ruby recognized it as an object. This was my final solution:
Classify takes the string and gives it the proper camelcase format so that it conforms to the model naming convention. Constantize then takes that string and converts it into an actual object.
Man, 2012’s gonna be IIiiiiiiintense!
(via 20twelve)
Lenny Kravitz Let Love Rule (Justice Remix) (via lennykravitz)
Carl Sagan - ‘A Glorious Dawn’ ft Stephen Hawking (Cosmos Remixed) (via melodysheep)
Really, this should be simpler. Knowing Rails folks there is probably some deep philosophical reason this isn’t included, but I hold no grudge.
So….I’m converting objects back and forth to JSON and when they return all my pretty Booleans are converted into strings. My assumption was that there was a handy little .to_b(ool) method for String, but alas there does not appear to be. This is the method I ended up writing.
As always I am open to suggestions and improvements.
I am writing this out of a bit of frustration. I have a solution here, but it took too long and it can not be correct. I am hoping some smarter folks will chime in with some thoughts.
I have a model called Questions which has many subtypes using single table inheritance. Basically types of questions dropdown, checkbox, radio, etc etc.
These are set up as resources so I can use restful routing. I also want to use all of the rails form magic so I set up resources like this…
map.resources :question_checkboxes, :as => :questions, :controller => :questions
This allowed the form_for method to render the form correctly and point to the “question” url instead of the url of one of the subtypes.
The next problem was that the “update” controller method was looking for very specific params “params[:question]”, but the rendered form was passing params like “params[:question_checkbox]”. The way I eventually solved this was set up a before filter and method in the controller like this…
before_filter :form_symbol
def form_symbol
if params[:question] then @form_symbol = :question end
if params[:question_checkbox] then @form_symbol = :question_checkbox end
end
and then in the update method of the questions_controller…
@question.update_attributes(params[@form_symbol])
It does the trick, but feels very uncomfortable. Suggestions and comments are welcome.