Archive for June, 2009

17
Jun
09

Super Easy Tabs in Rails

All the cool kids these days seem to be doing navigation via tabs, and since I want to be cool, too, I figured I might as well do it to. Ya, sure, there are plenty of plugins out there that do this, but it always seems like these things have too much configuration and code for its own good.

So, I went at it on my own and, really, if the tabs are simple, the solution is pretty simple. My tabs are based on the controller name, which means the current tab maps to all the actions of a certain controller. In other words, it’s kind of the way Basecamp does it.

First, let’s start with some code in the controller. In my app, everything that uses tabs is inherited from a base controller called LoginProtectedController. That’s where I put this code, but it would work just as well in the ApplicationController:

  helper_method :current_tab

  def self.current_tab(tab_name)
    before_filter do |controller|
      controller.send(:current_tab=,tab_name)
    end
  end

  protected

  def current_tab=(tab_name)
    @current_tab = tab_name
  end

  def current_tab
    @current_tab || controller_name.titleize
  end

So, this is what I have in one of my controllers to mark that the tab is not the name of the controller, but called ‘Dashboard’

  current_tab 'Dashboard'

Now for some helper code for displaying the tabs:

  def tab_link(args={})
    html_options = {}
    html_options = {:class=>'current'} if args[:tab] == current_tab
    link_to args[:tab], args[:path], html_options
  end

And here’s how you put it together in the view:

<div id="navigation">
  <%= tab_link("Dashboard", :path=>admin_path) %>
  <%= tab_link("Items", :path=>admin_items_path) %>
  <%= tab_link("Users", :path=>admin_users_path) %>
  <%= tab_link("Account", :path=>edit_admin_account_path) %>
</div>

If you want to make it look all pretty, some CSS should spruce it up:

#navigation {
  line-height: 100%;
  margin-left: 6px;
  float: left;
  font-size: 12px;
}

#navigation a {
  background-color: #CCCCCC;
  color: #000000;
  padding: 7px 15px;
  text-decoration: none;
  display: block;
  float: left;
  margin-left: 2px;
}

#navigation a:hover {
  background-color: #BBBBBB;
}

#navigation a.current, #navigation a.current:hover {
  background-color: #FFFFFF;
}

03
Jun
09

Proper DRM

The wife and I are planning a summer vacation to the northern parts of Japan, so instead of buying the whole guidebook for Japan, which runs at 35 bucks, we decided to buy the one chapter that we will actually use. This is a new idea by Lonely Planet and I think a great one, especially considering how much of the actual guide book people use when traveling. So, we went to their website, chose the chapter, and downloaded the PDF we were looking for. I almost assumed that there was some sort of DRM applied that would not let me print it or open it on another computer. However, I was wrong in this case. The text at the bottom of the PDF explains it all:

To make it easier for you to use, access to this chapter is not digitally restricted. In return, we think it’s fair to ask you to use it for personal, non-commercial purposes only. In other words, please don’t upload this chapter to a peer-to-peer site, mass email it to everyone you know, or resell it. See the terms and conditions on our site for a longer way of saying the above – ‘Do the right thing with our content.’

To which I say, good for them. There are too many instances of companies being super guarded with their content that they attach some sort of restrictions to what one can do with the content. And the reality is, if someone really wants to do something, they probably will. There are ways to get around just about any DRM protected file if you want and by locking it down, you are basically insulting your customers and telling them “I don’t trust you”.

Instead of not trusting their users, they’ve basically said “Listen, we know you can take this and give it to anyone you want. But, we trust that you won’t do that. Thanks!” And you know what? I won’t. I’ll keep it to myself and use it as if it were a real book.

I think it’s something to think about for all the software out there that has ridiculous pricing models based on the number of CPUs or users, etc or music download sites that restrict how the music you downloaded can be shared.   Make it easy for the customer and the customer will reward the company with loyalty and more revenue. Bog the customer down with restrictions and force him to spend more money upfront will lose future loyalty.




Stay Updated

or

Get new posts via email

Software Blogs - BlogCatalog Blog Directory

 

June 2009
M T W T F S S
« May   Jul »
1234567
891011121314
15161718192021
22232425262728
2930  

Follow

Get every new post delivered to your Inbox.