{"id":1695,"date":"2008-01-19T10:52:50","date_gmt":"2008-01-19T02:52:50","guid":{"rendered":"http:\/\/ihower.idv.tw\/blog\/archives\/1695"},"modified":"2008-09-29T01:02:21","modified_gmt":"2008-09-28T17:02:21","slug":"spakit-a-spa-rails-plugin","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/1695-spakit-a-spa-rails-plugin","title":{"rendered":"Spakit: A SPA Rails plugin"},"content":{"rendered":"<p><a href=\"http:\/\/rubyforge.org\/projects\/spakit\/\">Spakit <\/a>\u6e90\u81ea <a href=\"http:\/\/registrano.com\">registrano.com<\/a> \u548c <a href=\"http:\/\/blog.handlino.com\/2007\/07\/massage-spa-plugin-for-rails.html\">Massage<\/a>\uff0c\u662f\u4e00\u500b\u53ef\u4ee5\u8b93\u4f60\u5c07\u73fe\u6210\u7684\u7db2\u7ad9\u8f15\u9b06\u8f49\u63db\u6210 <a href=\"http:\/\/en.wikipedia.org\/wiki\/Single_page_application\">SPA<\/a> (single page application) \u7684 Rails Plugin\u3002\u53ea\u9700\u5728 view \u4e2d\u63db\u7528 Spakit helper\uff0c\u4e0d\u9700\u8981\u66f4\u52d5 controller code\uff0c\u5c31\u53ef\u5c07\u8d85\u9023\u7d50\u548c\u8868\u55ae\u9001\u51fa\u8b8a\u6210 Ajax \u9001\u51fa\u4e26\u66f4\u65b0\u9801\u9762\u3002<\/p>\n<p>spakit \u76ee\u524d\u653e\u5728 <a href=\"http:\/\/github.com\/ihower\/spakit\/tree\">github<\/a>\uff0c\u53e6\u5916\u4e5f\u5305\u6210 <a href=\"https:\/\/rubyforge.org\/projects\/spakit\/\">gem<\/a>\uff0c\u5b89\u88dd\u65b9\u5f0f\u5982\u4e0b:<\/p>\n<pre>\r\n gem install spakit\r\n cd \/your_rails_app\/vendor\/plugin\r\n gem unpack spakit\r\n mv spakit-0.9.0 spakit\r\n<\/pre>\n<p>\u4e26\u4e14 rename \u6210 spakit\u3002\u88dd\u597d\u4e4b\u5f8c\uff0c\u9996\u5148\u5efa\u7acb\u4e00\u500b Spakit \u5c08\u7528\u7684 Layout\uff0c\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\u5982\u4e0b:<\/p>\n<pre>\r\n# \/view\/layouts\/spakit.rhtml\r\n&lt;p&gt;&lt;%= flash[:notice] %&gt;&lt;\/p&gt;\r\n&lt;%= yield %&gt;<\/pre>\n<p>\u63a5\u8457\u5c31\u53ef\u4ee5\u4f7f\u7528 Spakit \u5c08\u7528\u7684 helpers\uff0c\u76ee\u524d\u6709 spakit_link_to, spakit_form_for \u548c spakit_form_tag \u4e09\u7a2e\u53ef\u4ee5\u4f7f\u7528\uff0c\u7528\u6cd5\u5982\u4e0b:<\/p>\n<pre>\r\nspakit_link_to 'new person', :url =&gt; new_person_path\r\nspakit_form_for @person, :url =&gt; people_path<\/pre>\n<p>\u5982\u6b64\u6309\u4e0b\u9023\u7d50\u6216\u9001\u51fa\u8868\u55ae\u5f8c\uff0cSpakit \u5c31\u6703\u9001\u51fa Ajax request(i.e. prototype&#8217;s Ajax.Updater )\uff0c\u7136\u5f8c\u5c07\u56de\u50b3\u7684 HTML \u7d50\u679c\u66f4\u65b0\u5230#content \u5340\u584a\u3002<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u8981\u652f\u63f4 Ajax \u7684 Histroy Bookmarks\uff0c\u5efa\u8b70\u53ef\u4ee5\u63a1\u7528 <a href=\"http:\/\/code.google.com\/p\/reallysimplehistory\/\">Really Simple History<\/a>(RSH) library \u4f86\u8655\u7406\u700f\u89bd\u5668\u7684\u4e0a\u4e00\u9801\u4e0b\u4e00\u9801\u554f\u984c\uff0c\u9019\u90e8\u4efd\u7684\u7bc4\u4f8b\u7a0b\u5f0f\u9644\u5728 plugin \u7684 <a href=\"http:\/\/spakit.rubyforge.org\/svn\/trunk\/README\">README<\/a> (\u4f7f\u7528\u5230 jquery library\uff0c\u597d\u5fc3\u4eba\u6709\u7a7a\u53ef\u4ee5\u5e6b\u5fd9\u5beb prototype version)\u3002<\/p>\n<p>P.S. \u9019\u7bc7\u6587\u7684\u82f1\u6587\u7248\u5728 <a href=\"http:\/\/handlino.com\/blog\/2008\/02\/17\/52\/\">Handlino&#8217;s blog<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spakit \u6e90\u81ea <a href=\"http:\/\/registrano.com\" class=\"autohyperlink\">registrano.com<\/a> \u548c Massage\uff0c\u662f\u4e00\u500b\u53ef\u4ee5\u8b93\u4f60\u5c07\u73fe\u6210\u7684\u7db2\u7ad9\u8f15\u9b06\u8f49\u63db\u6210 S &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/1695-spakit-a-spa-rails-plugin\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008Spakit: A SPA Rails plugin\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[33,5,53],"tags":[],"class_list":["post-1695","post","type-post","status-publish","format-standard","hentry","category-javascript","category-programming","category-rails","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q6tG-rl","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/comments?post=1695"}],"version-history":[{"count":0,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1695\/revisions"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=1695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=1695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=1695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}