所以我玩CoffeeScript,Rails 3.1所有好东西.我有一个资源,包含所有常用路由索引,显示,创建,编辑,更新,销毁.
索引视图的表单使用:remote => true如下:
<%= form_for @todo, :remote => true do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在创建控制器中,我有以下内容:
def create
@todo = Todo.new(params[:todo])
respond_to do |format|
if @todo.save
format.html { redirect_to @todo, notice: 'Todo was successfully created.' }
format.json { render json: @todo, status: :created, location: @todo }
format.js {render json: @todo }
else
format.html { render action: "new" } …Run Code Online (Sandbox Code Playgroud)