remote_functionではPost値を:withでいちいち指定する必要がある。 フィールドの数が多い場合は大変だ。

そういう場合、prototype.jsにForm.serialize('フォームのID')でフォームの値をname1=value1&name2=value2形式にしてくれる関数が便利である。

   1  <%= javascript_include_tag "prototype" %>
   2  <script language="JavaScript">
   3  function newArticle(){
   4      <%= remote_function(:url => {:action => :new},
   5                           :update => 'list',
   6                           :with => "Form.serialize('article')"
   7      ) %>
   8  }
   9  </script>
  10  

posted by Face ysakaki on Tue 19 Aug 2008 at 12:01

たとえばJavaScriptの都合などでactionがnewでもeditでもフォームタグのidが同じになって欲しいことがある。 そういう場合は:html=>{:name1=>'value1',:name2=>'value2'}でhtmlオプションを指定できる。

   1  <% remote_form_for(@article, :url => {:action => :update, :id => @article}, :update => 'list',:html=>{:id=> 'article'}) do |f| %>
   2  
   3    <%= render :partial=>f %>
   4  
   5    <p>
   6      <%= f.submit "保存" %>
   7    </p>
   8  <% end %>

posted by Face ysakaki on Tue 19 Aug 2008 at 11:56
Contents
Form.seriarizeでremote_functionの:withにフォームの値を設定する
remote_form_forでフォームタグのidを指定する
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ