Skip to content

Commit

Permalink
added ajax delete for microposts
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwooz committed May 22, 2012
1 parent 7d5b3ef commit 52d0d90
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 6 deletions.
Empty file.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
*= require_self
*= require_tree .
*/
#userlist {
background-color:white;
}
17 changes: 17 additions & 0 deletions app/assets/stylesheets/microposts.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@ body {
}
p#microcontent {
width:240px;
}
#micropost_container {
float:left;
}
#user_info {
background-color:white;
margin-left:400px;
border-radius:10px;
width:300px;
padding:20px;
border:solid black 1px;
}
.micro_hover {
background-color:#f33;
}
.micropost {
display:block;
}
7 changes: 4 additions & 3 deletions app/assets/stylesheets/users.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
#userlist {
background-color:white;
padding:10px;
}
2 changes: 1 addition & 1 deletion app/controllers/microposts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def destroy
@micropost.destroy
respond_to do |format|
format.html { redirect_to(@user) }
format.js { render :nothing => true }
format.js
end
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def index
respond_to do |format|
format.html # index.html.erb
format.json { render json: @users }
format.js
end
end

Expand Down
5 changes: 5 additions & 0 deletions app/views/microposts/destroy.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(document).ready(function() {
$('.delete_micropost').bind('ajax:success', function() {
$(this).closest('div').slideUp();
});
});
3 changes: 3 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<h1>List of Users</h1>

<% @users.each do |u| %>
<div id="#userlist">
<p><%= link_to u.email, user_path(u) %></p>
<p><%= u.microposts.count %> Microposts</p>
</div>
<% end %>
Empty file added app/views/users/index.js.erb
Empty file.
17 changes: 15 additions & 2 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<h1><%= @user.email %><div id="micropost_count">(<%= @user.microposts.count %> Entries)</div></h1><br/>
<div id="micropost_container">
<h1><%= @user.email %></h1><br/>
<% if logged_in? %>
<%= form_for [@user, @micropost], :remote => true do |f| %>
<h1>What are you thinking?</h1><br/>
Expand All @@ -11,4 +12,16 @@
<div id="microposts">
<%= render @user.microposts.reverse %>
</div>
<% end %>
<% end %>
</div>

<div id="user_info">
<h1>User Info</h1>
<hr />
<h3>
<%= @user.microposts.count %> microposts
</h3><hr/>
<h3>
Joined on <%= @user.created_at %>
</h3>
</div>

0 comments on commit 52d0d90

Please sign in to comment.