Giant Japanese Robot

Better living through pop culture.
Oct 31
Permalink

The Blob 1958 opening tune (via bubbazametti)

Comments (View)

Oct 16
Permalink

Ruby on Rails: String to Object

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:

object = params[:controller].classify.constantize.find(params[:id])

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.

Comments (View)

Oct 14
Permalink

RIP Captain Lou. You will be missed.

Comments (View)

Oct 07
Permalink
agentmlovestacos:

Man, 2012’s gonna be IIiiiiiiintense!
(via 20twelve)

agentmlovestacos:

Man, 2012’s gonna be IIiiiiiiintense!

(via 20twelve)

Comments (View)

Permalink

Lenny Kravitz Let Love Rule (Justice Remix) (via lennykravitz)

Comments (View)

Sep 25
Permalink

Carl Sagan - ‘A Glorious Dawn’ ft Stephen Hawking (Cosmos Remixed) (via melodysheep)

Comments (View)

Sep 18
Permalink

Ruby on Rails: String to Boolean

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.

  1.      def object_to_boolean(value)
  2.         return [true, “true”, 1, “1”, “T”, “t”].include?(value.class == String ? value.downcase : value)
  3.      end

As always I am open to suggestions and improvements.

Comments (View)

Sep 01
Permalink

Ruby on Rails: Single Table Inheritance and Restful Routes

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.

Comments (View)

Aug 26
Permalink
The other day I mentioned sketching a Zombie Totoro, looks like this person beat me to it.

The other day I mentioned sketching a Zombie Totoro, looks like this person beat me to it.

Comments (View)

Aug 20
Permalink

has_many :through & Acts_As_List

Following post is for Ruby on Rails geeks.

I don’t normally post my programming adventures here, but maybe I should. This is a simple thing and should have been obvious right away to me, but it wasn’t so I am posting it here for future generations. Thanks to Geek Mama for shaming me into posting this.

I have a “has_many :choices, :through => :question_items” model set up for Questions and their Choices. The QuestionItems model also has a”position” column because it is an Acts_As_List model. All is fine and good until I try and get the choices to return in the correct order by calling @questions.choices in my controller.

The solution was pretty simple, adding an :order option to the has_many method solved it:

has_many :choices, :through => :question_items, :order => "question_items.position"
Comments (View)

Aug 05
Permalink

nouvelle vague “dance with me” from bande a part (via luakabopper)

Comments (View)

Jul 23
Permalink

Kurtroll’d

Comments (View)

Jul 20
Permalink

Tricky Linguistics (via ayesham819)

Comments (View)

Jul 18
Permalink
(via reygunn)

(via reygunn)

Comments (View)

Jul 16
Permalink

Quirk Classics #2: Book Trailer (via irreference)

Comments (View)