Close and Go BackBack to Viget

Favorites

Announcing the ActionButton Plugin

Brian Landau
Brian Landau, Web Developer, June 19, 2008

When creating web application there’s often a need for single links that have a destructive or “unsafe” effect. In accordance with HTTP specs, GET’s (e.g. links) should not be used for this. The issues that 37signals had with unsafe links prove the importance of this.

This is also important if your application is RESTful. Rails offers a few good solutions, but none of them are ideal. There’s link_to_remote, but this requires the user to have JavaScript enabled and doesn’t allow for progressive enhancement. Then there’s submit_to_remote, which requires you to wrap it in a form tag yourself and also doesn’t allow for progressive enhancement. Last, you have button_to, which is almost ideal, but it uses a submit button that offers less options for styling than a button tag.

And this is where the idea for a button tag helper came in. (See this blog post for a good description of why the button element rocks). Thus, ActionButton was born.

With it, you can create a form with a single button element. The form can be set to point to any url just as you would with a normal form. The button and the form can have different id and class attributes, making them easy to target via JavaScript. But you don’t need to set these; by default it will create classes and ids that are sensible. Of course, all the normal HTML options are available, too.

The plugin will also install a modified version of the lowpro library. The ujs_remote_form helper provided creates a snippet of lowpro JavaScript that can be used to make a form (or set of forms) submit via an AJAX call.

So how would I use this?

Well, if you have a list of blog posts in an admin section and you want to add delete buttons next to each of them and you want them to look the same in every browser, this is how you would do it.

<%= action_button 'delete_post', "#{image_tag('icons/delete.jpg', :alt => 'delete')} Delete", 
post_url(post), {:method => :delete, :number => post.id} %>

Then when you’re ready for some AJAXy goodness, you can either use the Rails built-in helper of the plugin’s lowpro one:

Built-in:

Add this for each post:

<%= observe_form "delete_post#{post.id}-form", :on => 'submit', 
:confim => 'Are you sure you wish to delete this post?' %>

Lowpro:

Add this for the whole page of posts:

<%= ujs_remote_form 'button.delete_post', :confirm => 'Are you sure you wish to delete this post' %>

So where do I get this plugin of button joy?

It’s up on github right now!

If you have any questions, comments or suggestions, send them my way. It’s great to get feedback, but if you really feel I messed something up, just fork it and make the changes you feel it needs.

Inheritance is Unlikely

Justin Marney
Justin Marney, Former Staffer, June 05, 2008 What do you do when you identify common sets of shared behavior across several classes?

A common solution is to move the shared code into a base class and inherit.
# Filled with api interaction behavior
class Base
  def api_specific_behavior
    puts "connect to api"
  end
end

class User < Base
  def user_specific_behavior
    puts "I am a user"
  end
end
The problem with inheritance in this situation lies primarily in a subtle violation of the Liskov Substitution Principal which essentially states that inheritance should implement an "is-a" relationship. If we have a class called User that inherits from Base, are we trying to model the part of our domain where a User is a Base? This doesn't make sense given that we never actually have any Bases (i.e. instances of Base).

Continue reading "Inheritance is Unlikely"

From TextMate to ExpressionEngine

Patrick Reagan
Patrick Reagan, Development Director, May 01, 2008

Between writing code, documentation, and blog posts, I spend a lot of my time working in TextMate. It's an efficient text editor, but it becomes a bit of a headache when it's time to work on a new blog post. The real problem is my process:

  1. Open TextMate and start collecting my thoughts for a post in some cohesive fashion (optional)
  2. Finalize most of the content and basic formatting
  3. Copy the content into ExpressionEngine, tweak the formatting, add hyperlinks
  4. Preview the post and publish to the site

The reason for all this masochism is my dislike for editing content in a web-based form, WYSIWYG or otherwise. I love my editor enough that I'm willing to jump through some hoops in order to use it for the bulk of my editing work. But, there's a better way to do all this.

Continue reading "From TextMate to ExpressionEngine"

Right Way/Wrong Way: Closed Betas

Ben Scofield
Ben Scofield, Former Staffer, April 29, 2008

That’s right, everyone—it’s time for a thrilling episode of “Right Way/Wrong Way,” in which we see two possible solutions to a problem. One of ‘em’s good, one of ‘em’s bad, but we can all learn something from both of them!

This time: closed betas.

Continue reading "Right Way/Wrong Way: Closed Betas"

I Have a Pull Request on GitHub, Now What?

Patrick Reagan
Patrick Reagan, Development Director, April 24, 2008

I'm a n00b when it comes to Git, so I solicited Matt's help to get the changes in my fork up to our main GitHub account. As awesome as GitHub is, there's still no "automatically-pull-and-merge" functionality when someone wants to send you their changes (and for good reason). Here's how I made it happen:

The Scenario

I wanted to work on my constant_cache gem, so I forked the project into my own GitHub account. I made the changes I wanted, ensured that all specs were passing, committed, and then pushed the changes up to my repository. Now it was time to sync up those changes with the main repository.

Continue reading "I Have a Pull Request on GitHub, Now What?"

We're the Developers

at Viget Labs. We write about web development trends, tips, best practices, industry events, and our projects — all with an emphasis on Ruby on Rails.

Upcoming Events

Future Insights Live - April 29 to May 4
Future of Web Apps, Future of Web Design, Future of Mobile, and Future of Web in the Enterprise have joined forces to bring you our most comprehensive event EVER!

Contact Us

Have any questions, comments, ideas, or secrets to share? Let us know.


How many minutes in an hour?

Sorry, you need to have Javascript enabled to use this form. (Don't blame us, blame the spammers!) If you'd like to contact us, please visit our Contact page.