This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # worst thing you can do to someone in ruby? | |
| # fork this and add other evil | |
| class Module | |
| def method_added(method) | |
| undef_method method if rand > 0.999999 | |
| end | |
| end | |
| # Fun with forking |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PeopleController < ApplicationController | |
| def index | |
| @people = Person.all | |
| end | |
| def create | |
| @person = Person.new(params[:person]) | |
| @person.save! | |
| respond_to do |format| | |
| format.html { redirect_to people_url } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ul class="people"> | |
| <li style="display:none"></li> | |
| <% @people.each do |person| -%> | |
| <li><span class="name"><%= person.name %></span> <%= link_to 'delete', delete_person_path(person), :class => 'delete' %></li> | |
| <% end -%> | |
| </ul> | |
| <% form_for :person, :url => people_url, :html => {:class => 'people'} do |f| -%> | |
| <%= f.text_field :name %> <%= f.submit 'Add Person'%> | |
| <% end -%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% form_tag(person_url(@person)) do %> | |
| <%= hidden_field_tag :_method, 'delete' %> | |
| <p>Are you sure you want to delete <%= @person.name %>?</p> | |
| <%= submit_tag 'Delete' %> | |
| <%= link_to 'Cancel', people_url %> | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(){ | |
| Actions.connectAddForm(); | |
| Actions.connectDeleteLinks(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| connectAddForm: function() { | |
| $("form.people").submit(function() { | |
| $.ajax({ | |
| type: 'post', | |
| dataType: 'json', | |
| url: '/people', | |
| data: $(this).serialize(), | |
| success: function(json) { | |
| $('ul.people').append('<li><span class="name">' + json.person.name + '</span> <a href="/people/' + json.person.id + '/delete" class="delete">delete</a></li>'); | |
| $('#person_name').val(''); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| connectDeleteLinks: function() { | |
| $('ul.people').find('a.delete').live('click', function() { | |
| var li = $(this).parent(); | |
| if (confirm('Are you sure you want to delete the person "' + li.find('span.name').text() + '"?')) { | |
| $.ajax({ | |
| type: 'post', | |
| dataType: 'json', | |
| url: this.href.replace(/\/delete/, ''), | |
| data: {'_method': 'delete'}, | |
| success: function(json) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git clone git://github.com/aeden/unobtrusive-jquery-example.git | |
| cd unobtrusive-jquery-example | |
| script/server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <li><span class="name"><%= h person.name %></span> | |
| <%= link_to 'delete', delete_person_path(person), :class => 'delete' %> | |
| </li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('ul.people').append('<li><span class="name">' + | |
| html_sanitize(json.person.name) + '</span> <a href="/people/' + | |
| json.person.id + '/delete" class="delete">delete</a></li>'); |