· 1 min read
Screencast: jQuery Tokeninput
Download:
Download(21.7 MB, 11:09) Alternativer Download für iPod & Apple TV(20.4 MB, 11:09)
Resourcen:
Quellcode:
[bash] bundle rails g jquery:install [/bash]
[ruby] # Gemfile gem “jquery-rails”
# models/book.rb class Book < ActiveRecord::Base attr_accessible :name, :author_tokens has_many :authorships has_many :authors, :through => :authorships attr_reader :author_tokens def author_tokens=(ids) self.author_ids = ids.split(”,”) end end
# authors_controller.rb def index @authors = Author.where(“name like ?”, ”%#{params[:q]}%”) respond_to do |format| format.html format.json { render :json => @authors.map(&:attributes) } end end [/ruby]
[html] <%= stylesheet_link_tag “application”, “token-input-facebook” %> <%= javascript_include_tag :defaults, “jquery.tokeninput” %>
<%= f.label :author\_tokens, "Authors" %>
<%= f.text\_field :author\_tokens, "data-pre" => @book.authors.map(&:attributes).to\_json %>
[javascript] // application.js $(function() { $(“#book_author_tokens”).tokenInput(“/authors.json”, { crossDomain: false, prePopulate: $(“#book_author_tokens”).data(“pre”), theme: “facebook” }); }); [/javascript]