用Rails3和jQuery创建一个100% ajax CRUD应用
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
to
<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' %>
<%= javascript_include_tag 'rails' %>
?
????? <%= content_tag :h1, yield(:title) if show_title? %>
????? <%= yield %>
??? </div>
? </body>
?
<div id="post_form"><%= render :partial => 'form' %></div>
<div id="posts_list"><%= render :partial => "posts" %></div>
? <p>
??? <%= f.label :title %><br />
??? <%= f.text_field :title %>
? </p>
? <p>
??? <%= f.label :content %><br />
??? <%= f.text_area :content, :rows => 5 %>
? </p>
? <p><%= f.submit %></p>
<% end %>
Ps1: That uses html5 to make our forms and links remotes (:remote => true), so it's not gonna work in any version of INTERNET EXPLORER yet.
Ps2: You can also use the redirect/render in your actions pointing to the index and then create only one javascript view (index.js.erb) treating that as you want. I prefer to keep things separated in case I decide to change the visual behavior of some view.
Ps3: Someone should make a generator for this ajax forms.
?
?