A jQuery plugin to toggle Rails 2.x attributes
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


# MIT License
# Feel free to use it however you like. 
# Links back to http://github.com/thirdreplicator/troggle are appreciated.
.troggle( model_string, attribute_string, [plural form of model string] )

Description: This JQuery plugin is for toggling a Ruby on Rails 2.x attribute using
AJAX/jQuery with a standard fadeOut and fadeIn effect.  It assumes Rails 2.x with
authenticity token using format.json channel.  This plugin should work for any model
and attribute with a standard REST update function.  For models with irregular plural
forms, the irregular plural can be passed in as a third argument.

Just cut and paste the contents of troggle.js into your application.js and follow
the example below.

Required fields set in the Rails view:
AUTH_TOKEN: The rails authenticity token must be set in a javascript tag. 
iid:   the integer id of the model instance must be set on the displaying div tag
value: model.attribute must be set on the displaying div tag

HTML Example:
 <script type='javascript'>var AUTH_TOKEN = #{form_authenticity_token.inspect};</script>
 <div class="toggle_user_publish" iid='3' value='true'></div>  
 <div class="toggle_user_publish" iid='4' value='false'></div>  
 $('.toggle_user_publish').troggle("user", "publish");

HAML Example:
  var AUTH_TOKEN = #{form_authenticity_token.inspect}; #Required
  $(function() {
    $('.toggle_published').troggle("user", "publish");
- @users.each do |user|
  %div{ :class => 'toggle_published', \
        :id => "user_publish_#{user.id}", \
        :iid => "#{user.id}",                          # Required \
        :value=> "#{user.publish}" }                   # Required 
  = user_publish_string(user)