Saturday, September 24, 2011

Setting optional local variables in your partials

Rails' partials are great - but sometimes, it's a hassle maintaining them.

For instance, haven't you ever changed the name of a partial, and consequently had to go find all your renderings of that partial and tediously adjust the name?

Or, have you ever decided to add a local variable requirement to a partial, and then have to, again, find all your renderings of that partial and then adjust the :locals => { :some_variable_I_now_have_to_set => "some value that shouldn't exist for most partials" } appropriately?

I don't have a solution to the first one (though I certainly wish I did), but I do - hooray! - for the second.

Basically, if you're thinking of doing something like this in your partial file...
<% unless optional_local_variable.nil? %>
  
<% end %>
...you'll encounter an error saying that "optional_local_variable" is not defined, which is quite disturbing, considering that you wanted to check if it was nil to begin with.

So what do you do instead?
<% unless local_assigns[:optional_local_variable].nil? %>
  
<% end %>

Voila. What does this mean you can do? Here's a more complete example:

books/index.html.erb:
Books
<%= render :partial=>"partials/book", :locals=>{ :books=>@books } %>

partials/_book.html.erb:
<% unless local_assigns[:books].nil? %>
  The 'books' variable was passed.
<% else %>
  The 'books' variable was not passed.
<% end %>

stores/index.html.erb:
Stores - Featured
<%= render :partial=>"partials/book" %>

The stores/index file's partial call doesn't require the local variable that was passed into the partial call in books/index. Useful.

Basically, if you want to make the specification of a local variable in the render :partial call optional, use local_assigns[:variable_name].nil? This also checks to see that variable_name is nil if you specify :locals=>{ :variable_name=>nil }.

Thursday, September 22, 2011

When someone realizes your idea before you

What should you do when someone makes the thing that you've been dreaming of creating for years?

Smile & be genuine.
Try to make it better.
Ask yourself: Does it really make what you wanted? You probably wanted something different...
Just relax... go about your ways, discovering, embracing.

If it helps, treat life as a discovery process.

Sunday, September 18, 2011

The Stigma of Video Games

I don't play video games much. Honestly. I remember a time when I was addicted to a few games, but into high school and college, I stopped playing entirely simply because of countless other activities I deemed "more important."

But since I'm at the University of Southern California, which has (apparently) the best game design program in the country, I began pondering video games more. I started considering the stigma video games have and how gaming is similar to reading, a highly praised educational activity.

Someone who reads a lot gains credibility. He becomes a knowledgeable person. But someone who plays video games a lot doesn't gain this same credibility, although he no doubt learns things too.

Is this right? Should gaming have such a stigma?

Reading and playing video games share many similarities. You learn. You "get lost in a different world." You, potentially, become isolated from others. (In the case of reading, you might be reading in a group, and in the case of video games, you might be playing with others, but often, reading or playing video games would isolate you from surroundings.) Your mind is engaged and focused. They're similar...

I remember a conversation I had with a good friend about how video games should be viewed as credible an element to society as literature. So many novels have literary merit, and the educated members of society are proud to have read such novels. But games? What if games had "literary merit" too? They're so complex - perhaps even more so, what with the direct interaction with people. What if we could view the various elements of a video game - graphics, storyline, themes, meaning, representation of life, music, and more - and appraise the game just like we appraise literature?

If games were clearly educational, and if they didn't have the mild stigma they do, what would society be like?

#rambling thoughts...

EDIT ===
Here's an interesting link about video games being the next great art form: http://www.salon.com/books/feature/2010/06/20/tom_bissell_extra_lives_interview_ext2010

I got to think more about this. Perhaps the usage of the word "game" in "video games" limits our understanding and ability to see that video games are more than that. Ever read 1984 by George Orwell or Outliers: The Story of Success by Malcolm Gladwell? If you have, you'd know that limiting language/vocabulary influences thinking. By having the word "game" associated with video games, people have a harder time grasping the artistic and "literary" value of video games. This is probably because we associate "game" with so many childhood things - tic-tac-toe is a game, and so are board games, little puzzles...

Maybe we need a whole new term for video games.

Friday, September 9, 2011

Education, Adulthood

I just went to an outstanding lecture by Cathy N. Davidson and hosted by the University of Southern California's Visions and Voices program. Her lecture was about the science of attention, and how it transforms and should transform "the way we live, work and learn."

Although many great ideas emerged from this lecture, there were several that really hit me about education.

She asked the crowd about the history of the multiple choice test. Have you ever thought about that? This type of test has just become so classic that most people don't even question its existence.

Anyway, she asserted that the inventor of the multiple choice test actually made it ad hoc to deal with the many immigrants of the early 20th century. The key phrase in that sentence is "ad hoc." This test was only meant to handle the emergency of too many immigrants! The inventor had no idea - and especially no desire - for the test to be adopted by colleges. The inventor, in fact, was horrified that his invention became what it has, and he spent much of the remainder of his life denouncing his creation. Even when he held a prominent position at the head of a university, he advocated getting rid of this test. And unfortunately, he was fired because of this.

The problem with the test is obvious: it tests limited knowledge. It narrows the playing field and eliminates direct application to real life. Of course, it's convenient for testing little things - facts, figures, etc. But for higher education, it's a terrible limitation. These tests are only good for lower-order skills, and lower-order skills are insignificant as students progress through high school, college, and beyond. Ultimately, these tests fail for the journey to adulthood.

Adulthood. That was another part that the speaker made an interesting note about. She explained how, on the last class of a course she once taught, she gave the students a simple task: Write down a few questions you want to ask me (i.e. her) on this last day we have together. Then, she said she was going to leave the room and let the class compare, altogether, what they wrote, because in the end she was only allowing one question. The students had to discuss their ideas, negotiate, and agree on just one question.

When she  returned, she saw that the students had a smirk on their faces. It was evident they had a good question. And when they asked, her breath was taken away:

"How do we become adults?"

Education prepares us so superficially for the real world. So many students know the books and know how to conquer the multiple choices and know how to snag the "A" in class. But what happens when you graduate? What happens when you finally face the real world, the world that our superficial educational system fails to prepare us for?

Now I ask my own question: How could these students come up with such a profound question to ask? The collaboration environment the teacher created by leaving the room and letting the students figure things out was powerful. Anyone can conquer a system; like I said, anyone can grab that "A" in class, or master those multiple questions. But to really learn, we need the interaction that has brought mankind from hunter-gatherer to farmer to scholar to... today.

Collaboration - and the lesser role of the teacher - is a huge idea that education should implement. The traditional establishment of the teacher standing up in front of the class, presumably the master of the subject at hand, while the students sit in rows facing the teacher is a failed concept that should soon be wiped away. It precludes the collaboration that is so essential in the real world and lays the cornerstone for false beliefs that the teacher "knows it all."

Alright. I wrote this post in a rush to let my ideas flow from my mind. Still, I needed to write this because the lecture was really moving. I definitely left out a lot, but I wanted to mention what I have. Before ending this, though, I want to share a few statements that, at least to me, capture key ideas that have changed the way I think. These are phrases that came to mind while listening to this great speaker.

"The multiple choice test should fade away."
"Institutions are difficult to change."
"Remove the teacher and let the students explore."
"Take away the grading and let the real learning begin."
"How do we become adults?"

Friday, September 2, 2011

Google+'s Age Restriction

Google's expanding strategy with Google+ is incredibly interesting.

Restricting the age minimum to 18 has encouraged the adults of society to latch on - major politicians, established workers, and more - something in which Facebook is lagging, what with the mild social stigma behind an adult using Facebook (e.g. it feels awkward when you get a friend suggestion for your best friend's dad, and it's admittedly a bit odd seeing your high school teacher on Facebook).

Further, this strategy encourages anticipation from those below 18 to get a G+ as soon as they turn 18.

I personally find it even more intriguing since it's not only the age at which someone is officially an adult and can participate in contracts with Google; it's also, roughly, the age at which a high school student becomes a college student, which is a major transition socially in that student's life.