{"id":1497,"date":"2006-10-17T22:35:40","date_gmt":"2006-10-17T14:35:40","guid":{"rendered":"http:\/\/ihower.idv.tw\/blog\/archives\/1497"},"modified":"2008-09-29T01:09:01","modified_gmt":"2008-09-28T17:09:01","slug":"rails-rjs-templates-%e5%88%9d%e9%ab%94%e9%a9%97","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/1497-rails-rjs-templates-%e5%88%9d%e9%ab%94%e9%a9%97","title":{"rendered":"Rails RJS Templates \u521d\u9ad4\u9a57"},"content":{"rendered":"<p><a href=\"http:\/\/oreilly.com\/catalog\/rjsrails\/\"><img decoding=\"async\" src=\"http:\/\/oreilly.com\/catalog\/covers\/0596528094_cat.gif\" style=\"float: left; margin: 5px; border: 0px; padding: 5px\" \/><\/a>RJS templates \u662f Rails 1.1 \u4e2d\u7684\u4e00\u7a2e\u65b0 template\uff0c\u5b83\u7684\u958b\u767c\u8005 <a href=\"http:\/\/conio.net\/\">Sam Stephenson<\/a>\u00a0\u4e5f\u662f<a href=\"http:\/\/prototype.conio.net\/\"> Prototype.js<\/a> \u7684\u4f5c\u8005\u3002\u4e0d\u50cf\u4e00\u822c template \u7522\u751f HTML \u6216 XML\uff0cRJS templates \u7522\u751f Javascript (based on prototype) code \u50b3\u7d66\u700f\u89bd\u5668\u57f7\u884c\uff0c\u4f60\u53ef\u4ee5\u5728 template \u4e2d\u4e00\u6b21\u4fee\u6539\u9801\u9762\u591a\u500b\u5730\u65b9\uff0c\u800c\u6240\u6709 template \u8a9e\u6cd5\u7686\u662f\u7528 Ruby \u4f86\u5beb\u3002<\/p>\n<p>\u8981\u5b78RJS template\uff0c\u76ee\u524d\u6700\u597d\u7684\u6587\u4ef6\u61c9\u8a72\u5c31\u662f\u9019\u4efd <a href=\"http:\/\/www.codyfauser.com\/articles\/2005\/11\/20\/rails-rjs-templates\">Cody Fauser<\/a> \u6240\u5beb\u7684 <a href=\"http:\/\/oreilly.com\/catalog\/rjsrails\/\">RJS Templates for Rails<\/a> \u4e86\uff0c\u76f4\u63a5\u7dda\u4e0a\u8cb7PDF\u7248(\u4e5f\u53ea\u6709PDF\u7248)\uff0c\u800c\u4e14\u4f5c\u8005\u6703\u66f4\u65b0\uff0c\u6211\u624b\u4e0a\u7684\u662f 9\/26\u3002\u53e6\u5916 slash7 \u63d0\u4f9b\u4e86\u4e00\u4efd\u6f02\u4eae\u5716\u4f8b <a href=\"http:\/\/www.slash7.com\/articles\/2006\/10\/8\/rjs-demistified-with-pretty-colors\">RJS Demystified With Pretty Colors!<\/a>\u3002RubyInside \u5247\u6709\u6574\u7406\u4e86\u4e00\u4efd<a href=\"http:\/\/www.rubyinside.com\/16-rjs-resources-and-tutorials-for-rails-programmers-5.html\"> 16 RJS Resources and Tutorials for Rails Programmers<\/a>\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b<a href=\"http:\/\/rails.ihower.idv.tw\/rjs1\">\u7c21\u55ae\u7684Ajax\u7bc4\u4f8b<\/a>\uff0c\u9700\u8981\u5beb\u7684\u7a0b\u5f0f\u78bc\u5f88\u5c11\uff0c\u800c\u4e14\u91cd\u9ede\u662f\u4e0d\u9700\u8981\u5beb JavaScript\u3002<!--more--><\/p>\n<p>\u9996\u5148\u5efa\u7acb Controller \u53ca\u5169\u500b action index\u8ddfnote<br \/>\nruby script\/generate controller Rjs1<\/p>\n<blockquote><p>#\/app\/controllers\/rjs1_controller.rb<br \/>\nclass Rjs1Controller &lt; ApplicationController<br \/>\n\u00a0def index<br \/>\n\u00a0end<br \/>\n\u00a0def note<br \/>\n\u00a0@note = params[:note]<br \/>\n\u00a0end<br \/>\nend<\/p><\/blockquote>\n<p>\u9019\u662f\u642d\u914d action index \u7684\u00a0HTML template\uff0c\u6709\u4e00\u500bAjax\u7684\u8868\u55ae\u8f38\u5165\u6846\u3002\u4ee5\u4e0b\u7701\u7565 html \u7684\u524d\u5f8c\uff0c\u8a18\u5f97head\u88e1\u8981\u52a0 &lt; %= javascript_include_tag :defaults %&gt; \u4f7f\u7528 prototype.js\u3002<\/p>\n<blockquote><\/blockquote>\n<blockquote><\/blockquote>\n<blockquote><p>#\/app\/views\/rjs1\/index.rhtml<br \/>\n&lt; %= form_remote_tag :url =&gt; { :action =&gt;&#8217;note&#8217; }, :html =&gt; {:id=&gt;&#8217;note-form&#8217; } %&gt;<br \/>\n&lt; %= text_field_tag &#8216;note&#8217;,nil,:size =&gt; 40 %&gt;<br \/>\n&lt; %= submit_tag &#8216;submit&#8217; %&gt;<br \/>\n&lt; %= end_form_tag %&gt;<\/p><\/blockquote>\n<p>\u91cd\u982d\u6232\uff0c\u9019\u662f action note \u7528\u7684 RJS template\uff0c\u7b2c\u4e00\u884c\u5728 id=&#8221;notes&#8221; \u7684\u5143\u7d20\u88e1\u9762\u63d2\u5165 partial template \u5340\u584a\uff0c\u7b2c\u4e8c\u884c\u52a0\u7279\u6548\uff0c\u7b2c\u4e09\u884c\u91cd\u8a2d\u8868\u55ae\u3002<\/p>\n<blockquote><p>#\/app\/views\/rjs1\/note.rjs<br \/>\npage.insert_html :bottom, &#8216;notes&#8217;, :partial =&gt;&#8217;note&#8217;<br \/>\npage.visual_effect :highlight, &#8216;note&#8217;<br \/>\npage.form.reset &#8216;note-form&#8217;\u00a0<\/p><\/blockquote>\n<p>\u9019\u662f\u4e0a\u8ff0\u7528\u5230\u7684 partial template\uff0c\u9019\u88e1\u7684 note \u8b8a\u6578\u900f\u904e Controller \u4e2d\u7684 @note \u50b3\u9032\u4f86\u4f7f\u7528\u3002<\/p>\n<blockquote><p>#\/app\/views\/rjs1\/_note.rhtml<br \/>\n&lt; %= Time.now.to_s %&gt;<br \/>\n&lt; %=h note %&gt;<\/p><\/blockquote>\n<p>\u4ed4\u7d30\u60f3\u60f3RJS templates\u7684\u6982\u5ff5\uff0c\u4f60\u6703\u89ba\u5f97\u975e\u5e38\u6709\u610f\u601d\uff0c\u5be6\u5728\u662f\u878d\u5408\u7684\u975e\u5e38\u6f02\u4eae\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>RJS templates \u662f Rails 1.1 \u4e2d\u7684\u4e00\u7a2e\u65b0 template\uff0c\u5b83\u7684\u958b\u767c\u8005 Sam Step &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/1497-rails-rjs-templates-%e5%88%9d%e9%ab%94%e9%a9%97\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008Rails RJS Templates \u521d\u9ad4\u9a57\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":[9,33,5,53],"tags":[],"class_list":["post-1497","post","type-post","status-publish","format-standard","hentry","category-books","category-javascript","category-programming","category-rails","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q6tG-o9","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1497","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=1497"}],"version-history":[{"count":0,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1497\/revisions"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=1497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=1497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=1497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}