|
Scope a variable to a block...
Sometimes you are coding a template and you need to refer to the same method chain over and over. For example, you’re coding a template that summarizes activity on recent messages. You iterate through a block of messages, and for each message you want to display some information pertaining to the last comment. You could do it like this:
<div class="active_messages">
<% @active_messages.each do |message| %>
<h1><%= message.title %></h1>
<div class="latest_comment">
<div class="avatar">
<%= avatar_for(message.comments.last.creator) %>
</div>
Latest comment <%= time_ago_in_words(message.comments.last.created_at) %> ago by <%= message.comments.last.creator.full_name %>
</div>
<% end %>
</div>
Everything inside of div.latest_comment deals with the exact same comment, but we have to use a method chain to get the comment each time (message.comments.last).
One solution is to set a local variable inside the iterating block with the knowledge that the variable will be reset after each iteration:
<div class="active_messages">
<% @active_messages.each do |message| %>
<h1><%= message.title %></h1>
<% comment = message.comments.last %>
<div class="latest_comment">
<div class="avatar">
<%= avatar_for(comment.creator) %>
</div>
Latest comment <%= time_ago_in_words(comment.created_at) %> ago by <%= comment.creator.full_name %>
</div>
<% end %>
</div>
One on hand, this is better because the methods called on `comment` are easier to scan. The whole div.latest_comment is more readable without the repeated method chain. On the other hand, setting a local variable is bad style. The local variable assignment creates state without explicitly showing where that state applies. It feels a little too PHP for my taste.
A better approach is to use the `tap` method to scope a variable to a block:
<div class="active_messages">
<% @active_messages.each do |message| %>
<h1><%= message.title %></h1>
<div class="latest_comment">
<% message.comments.last.tap do |comment| %>
<div class="avatar">
<%= avatar_for(comment.creator) %>
</div>
Latest comment <%= time_ago_in_words(comment.created_at) %> ago by <%= comment.creator.full_name %>
<% end %>
</div>
<% end %>
</div>
The `tap` block shows exactly where the scope of the assignment starts and ends. I like how the template explicitly says “now we are going to deal with a comment in the following section, and this is the comment we are working with.”
I just hit on this pattern today while working on a feature and I think it’ll come in handy in the future.
|
|
Descriptive words and phrases...
- Extremely mild
- Richly foaming
- Naturally gentle
- Deeply cleanses
- Nourishes
- Pure and soothing
- Synergistically
- Refresh and restore
- Skin radiance
- Cool soothing
- Protects and restores balance
- Harmonize and replenish
- Additional moisturizing benefit
What doesn’t this stuff do? Lather up and this naturally gentle, richly foaming, pure and soothing nourishing cleanser will synergistically refresh, harmonize, replenish, protect and restore balance with cool soothing botanicals.
Kinda ridiculous, isn’t it? Reading this should remind you to read your own site, your own marketing copy, your own definitions.
What claims are you making? Do you really believe them? What are you saying? Does it make any sense? How are you describing your product? Is it accurate or just a sea of adjectives that look good and sound good together? What story are you telling or selling? Whatever it turns out to be, are you really OK with it? Deep down inside, is it something you’re proud of?
|
|
INSIGHT: When debating UI, a...
When debating UI, a picture is better than a description. And a functional mockup is better than both. But debating UI without being able to look at something is a waste of time.
|
|
A Quick Look at Mobile Web...
Designing for the mobile web is not the same as designing for the traditional web, and though as an industry we're just learning as we go, we have to learn to adapt quickly to these new demands. Let's take a quick look at some concepts to keep in mind when designing for the mobile web.
|
|
Frightened, clueless or...
In the face of significant change and opportunity, people are often one of the three. If you're going to be of assistance, it helps to know which one. Uninformed people need information and insight in order to figure out what...
|
|
Measuring Real Success Online...
|
|
Common Misconceptions about...
Here are some common misconceptions about being a web designer that just aren't true.
|
|
The least I could do
One way to think about running a successful business is to figure out what the least you can do is, and do that. That's actually what they spent most of my time at business school teaching me. No sense putting...
|
|
There Is Nothing Wrong With...
For some reason, no one in Social Media is really allowed to make any money. It's verboten. It's against the community spirit. It's the wrong thing to do.
That's just, plain stupid. Yes, the new digital channels are primed for those who are looking to connect, communicate and engage in conversations, but if there is no benefit in the end, then all is lost. For some, that end benefit will be dollars in the bank, for others it will be social capital (check out Tara Hunt's amazing book, The Whuffie Factor, for more on that), for some it will be the growth of their personal brand (which in turn will help them create ventures in other channels for monetary gain), and others do it simply as a way to stay connected and learn from more people.
It takes all kinds.
One ring does not rule them all in this instance. So, before we go pointing fingers at those who are developing and nurturing their own communities for their own financial gain (and charging access to them), always remember that the most amazing thing about these platforms is that it's not like mass media that is being shoved down all of our collective throats. It's not a stack of flyers that someone is dumping in your mailbox every other day that you can't ignore. The true magic of these channels and platforms is the choice. Personally, I live in a "no spam" world within my online communities because I simply unsubscribe, unfollow and unfriend those who are using the channels in ways in which I am not interested in.
Be honoured to be able to pay for the good stuff.
Sure, there is tons of brilliant and free content online. From following certain individuals on Facebook and Twitter to specific Blogs and Podcasts that no one should be without, but along with that, there is tremendous value in paying for access to certain online communities, buying reports, paying for e-books and online courses, etc... It's not only a great way for the content producer to make a living, it's great (and usually cheap-ish) way for the audience to get a boost of information and knowledge. The amazing thing about all of this is that it's pretty simple and easy (just do a quick search engine reference check) to know who the snake oil salespeople are from the legit businesspeople (if you're still not sure, just look to see what their refund policy is and how quickly they are to respond to any questions you may have about the product or service prior to purchase). Sure, there are many scumbags online (just like in real life), but with a little due diligence, it's fairly obvious where the gold lies.
It's a transition we all knew was coming.
Free is great, but at a certain point that well runs dry (for more on that, read Chris Anderson's book, Free). People are willing to pay for things like access, unique content, premiums, artefacts, etc... Creating platforms that add value to a community is worthwhile (and worth the cost). No one ever said that everything in Social Media has to be free... and even free has a cost associated to it.
What do you think? Is it wrong to use Social Media to make money?
Tags:
blog
choice
chris anderson
communication
community
content producer
conversation
digital channel
ebook
facebook
free
free content
information
knowledge
making money
mass media
online community
online course
paid content
personal brand
podcast
premium
search engine
social capital
social media
tara hunt
the whuffie factor
twitter
unfollow
unfriend
unsubscribe
|
|
The Economist had a field day...
|
|
iPad app of my dreams: the...
Here's the spec. If you build it and it's great, I'll use it and I'll blog it. A while ago, I posted about the talking pad and a modern version of it. I think there's a killer app version of...
|
|
15 Fantastic Finds on the...
Google Code Repository is a section of Google that, just like SourceForge, allows developers to upload their code for others to use under license. The repository was launched in 2006 and after searching through its archives, I found a number of interesting scripts and other goodies that would be an asset in any website owner/website builder's arsenal.
|
|
Exploded Settings icon
http://www.buyolympia.com/q/Item=settings-app-shirt
|
|
The Days of Miracles and...
http://www.eod.com/blog/2010/02/the-days-of-miracles-and-wonde/
|
|
What Motivates You?
There are some people who do the heavy lifting when it comes to thinking about why human beings do the things we do.
Dan Pink (aka Daniel H. Pink) is one of those thinkers. He's the author of some of the best (and best-selling) business books like Free Agent Nation, A Whole New Mind, The Adventures of Johnny Bunko (the first American business book done in Japanese manga) and his recently-released hit, Drive - The Surprising Truth About What Motivates Us. Here's how his Blog describes Drive:
"Drawing on four decades of scientific research on human motivation, Pink exposes the mismatch between what science knows and what business does -- and how that affects every aspect of life. He demonstrates that while carrots and sticks worked successfully in the twentieth century, that's precisely the wrong way to motivate people for today's challenges. In Drive, he examines the three elements of true motivation -- autonomy, mastery, and purpose -- and offers smart and surprising techniques for putting these into action. Along the way, he takes us to companies that are enlisting new approaches to motivation and introduces us to the scientists and entrepreneurs who are pointing a bold way forward. Drive is bursting with big ideas -- the rare book that will change how you think and transform how you live."
Do you think Google knows what motivates people?
During a recent promotional book tour, Pink stopped off at the Googleplex in Mountain View, California (on January 15th, 2010), for an amazing Google Talk. You can watch the one-hour presentation right here (and yes, it's well worth the time commitment): YouTube - Leading@Google - Daniel Pink.
P.S. - Pink is also a contributing editor at Wired Magazine.
Tags:
a whole new mind
best-selling author
blog
book tour
business
business book
dan pink
daniel h pink
drive
entrepreneur
free agent nation
google
google talk
googleplex
human motivation
manga
motivation
presentation
the adventures of johnny bunko
thinking
wired magazine
youtube
|
|
Find me at...
|
|
New Gel Video: Jamy Ian Swiss
There is one key ingredient in all good magic tricks, and Jamy Ian Swiss reveals it before taking the audience through a magic trick as shown from the magician's perspective. This is one of the most thought-provoking and talked-about presentations from Gel 2009 and should be required viewing for anyone in the business of creating good experiences. (Hint: the key ingredient is also the essence of good listening.)
See also:
• Jamy's website
• Pomegranates and empathy (and another reference in Deception considered helpful)
|
|
Events in 2010
This year will be a busy one in terms of speaking events. I’m currently crafting a brand new talk titled, “The CSS3 Experience”. It’ll focus on enriching the experience layer with advanced CSS and CSS3. Everyone can easily add enhancements to to their designs when focusing on the interactions and events that happen on the [...]
|
|
Using SVG for Flexible,...
In Part II, dig deeper into the technology behind using SVG for your site design. Explore how to incorporate SVG in a cross-browser friendly manner, including using SVGWeb to ensure that the SVG shows in Internet Explorer. And discover the unique characteristic that makes SVG ideal for page backgrounds: scalability.
|
|
Using SVG For Flexible,...
Many of us think of Scalable Vector Graphics (SVG) as an also-ran: fine for charts and tables, but not much else. Yet SVG can actually enhance a site’s overall design, and can be made to work in even the most stubborn browser. In Part I of a two-part series, Shelley Powers covers important basics of working with SVG, including browser support and accessibility.
|
|
The Survey, 2009
For the third year in a row, good citizens of the web, we ask that you take a few minutes to tell us about your professional skills, educational background, career prospects, job benefits, and more.
|