Skip to content

benhutton/action_button

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Original version at http://github.com/vigetlabs/action_button. This version removes the LowPro AJAX code.

ActionButton

This provides helpers for creating a non-AJAX form containing a single button element. Using a button element allows the actions to be safe, not javascript dependent, and easily styled.

Methods and Options

  • button_tag (name, content, type, html_options)
    • name: the name and id attribute of the button
    • content: the content inside the open/close tags
    • type: submit, reset, or button
  • action_button (name, content, url_for_options, options)
    • name: the name and id attribute of the button
    • content: the content inside the button open/close tags
    • url_for_options: same as for link_to, and form_for, etc.
    • options:
      • accepts all normal HTML options that are generally available on content_tag
      • :wrapper_tag - this takes a symbol for the tag name to be used around the button default is :p
      • :form_class - set's the class attribute for the form tag
      • :form_id - set's the id attribute for the form tag
      • :wrapper_class - set's the class for the wrapper tag. default: nil

Examples

Create a delete button:

action_button 'delete-comment', 'Delete this Comment', comment_path(@post, comment), {:method => :delete, :number => comment.id}

Produces:

<form action="/posts/5/comments/12" class="delete-comment-form" id="delete-comment12-form" method="post">
   <div style="margin:0;padding:0">
      <input name="_method" type="hidden" value="delete" />
   </div>
   <p>
      <button class="delete-comment" id="delete-comment12" name="delete-comment12" type="submit">Delete this Comment</button>
   </p>
</form>

Embed an image and use custom classes and id for easier styling:

action_button 'delete-comment', image_tag('icons/delete.png', :alt => 'Add a Comment'),
                                new_comment_path(@post),
                                { :id => "commentDel", :class => 'delComment', 
                                  :form_class => 'delComment', :form_id => "delCommentForm" }

Produces:

<form action="/posts/5/comments/12" class="delComment" id="delCommentForm12" method="post">
   <div style="margin:0;padding:0">
      <input name="_method" type="hidden" value="delete" />
   </div>
   <p>
      <button class="delComment" id="delComment12" name="delComment12" type="submit">
        <img src="/images/icons/delete.png" alt="Delete this Comment" />
      </button>
   </p>
</form>

License

Copyright (c) 2008 Brian Landau of Viget Labs, released under the MIT license

About

A Rails plugin for creating a non-AJAX form containing a single button element. Allowing actions to be both safe, not javascript dependent and easily styled.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%