Giant Japanese Robot

Better living through pop culture.
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)

Jul 13
Permalink

Bionic Woman - Bigfoot (via LincolnAP)

Checklist

  1. Afro Bigfoot
  2. Best hair on television
  3. Purple and yellow speedsuits
  4. Anti-gravity rock throwing
  5. Utility belts
  6. Socially acceptable paunch
Comments (View)

Jul 02
Permalink

Interview with Danny from The Shining (via Spiralendrache)

Comments (View)

Jul 01
Permalink

Bollywood He-Man

Bonus dime store Orco.

Chahiye He Man He Man from Nafrat Ki Aandhi (1989) (via jatholb)

Comments (View)

Jun 08
Permalink

Earlier version of Dune that never was

From Wikipedia:

In December 1974, a French consortium led by Jean-Paul Gibon purchased the film rights from APJ. Alejandro Jodorowsky was set to direct. In 1975, Jodorowsky planned to film the story as a ten hour feature, in collaboration with Orson Welles, Dan O’Bannon, Salvador Dalí, Gloria Swanson, Hervé Villechaize and others (whom he nicknamed his “seven samurais”). The music would be composed by Pink Floyd. Jodorowsky set up a pre-production unit in Paris consisting of Chris Foss, a British artist who designed covers for science fiction periodicals, Jean Giraud (Moebius), a French illustrator who created and also wrote and drew for Metal Hurlant magazine, and H. R. Giger. Moebius began designing creatures and characters for the film, while Foss was brought in to design the film’s space ships and hardware. Giger began designing the Harkonnen Castle based on Moebius’ storyboards, and Dali was cast as the Emperor with a reported salary of $100,000 an hour. Jodorowsky also hired Dan O’Bannon to head the special effects department.


I love the Lynch version but that would have been unicorn magic right there.

Comments (View)

Permalink
agentmlovestacos:

The same person (kid?) also sent me an email addressed to Daredevil. Also adorable.

agentmlovestacos:

The same person (kid?) also sent me an email addressed to Daredevil. Also adorable.
Comments (View)

Jun 04
Permalink

From the Stretch Armstrong press release

“Stretch Armstrong is a character I have wanted to see on screen for a long time,” said Imagine Entertainment’s Brian Grazer. “He’s an unconventional kind of super hero with a power that no one would want. It’s a story about a guy stretching – if you will – the limits of what is possible to become all that he can be.”

Comments (View)

Jun 02
Permalink
Remake: America (via bjepson)

Remake: America (via bjepson)

Comments (View)