Last active
December 19, 2015 14:29
-
-
Save delba/5969191 to your computer and use it in GitHub Desktop.
client id
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 Item < ActiveRecord::Base | |
| 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).on 'submit', '#new_item', (e) -> | |
| e.preventDefault() | |
| $.ajax | |
| type: 'POST' | |
| url: '/items' | |
| dataType: 'json' | |
| data: $(this).serialize() | |
| beforeSend: (xhr) => | |
| xhr.cid = Date.now() | |
| $(this).after "<article id='#{xhr.cid}'> #{item_name.value} </article>" | |
| @reset() | |
| success: (item, status, xhr) -> | |
| $("##{xhr.cid}").replaceWith "<article id='#{item.id}'> #{item.name} </article>" |
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 ItemsController < ApplicationController | |
| respond_to :json | |
| def create | |
| @item = Item.create(item_params) | |
| respond_with @item | |
| end | |
| private | |
| def item_params | |
| params.require(:item).permit(:name) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment