티스토리 뷰
app/views/users/index.html.erb
<div id="users">
<%= render @users %>
</div>
<%= form_for(User.new, remote: true) do |f| %>
<%= f.label :name %><br/>
<%= f.text_field :name %>
<%= f.submit %>
<% end %>
app/views/users/_user.html.erb
<%= div_for user do %>
<%= link_to "User #{user.name}", user %>
<div class="actions">
<%= link_to 'edit', edit_user_path(user) %>
<%= link_to 'delete', user, method: :delete, remote: true %>
</div>
<% end %>
app/controllers/users_controller.rb
class UsersController < ApplicationController
def create
@user = User.new(params[:user])
end
def destroy
@user = User.find(params[:id])
@user.destroy
end
end
app/views/create.js.erb
<% if @user.new_record? %>
$('div#users').append("<%= escape_javascript(render @user) %>");
<% else %>
...
<% end %>
app/views/users/destroy.js.erb
$('#<%= dom_id(@user) %>').fadeOut();