Skip to content
Browse files

Display shouts in partials for dashboard and users.

  • Loading branch information...
1 parent 8d814c8 commit ce099c42dd27c93f5b6f532f25d3ce94b0c84343 @halogenandtoast committed
View
1 app/controllers/dashboards_controller.rb
@@ -1,5 +1,6 @@
class DashboardsController < ApplicationController
def show
@shout = Shout.new
+ @shouts = current_user.shouts.current
end
end
View
5 app/controllers/shouts_controller.rb
@@ -1,7 +1,12 @@
class ShoutsController < ApplicationController
+ before_filter :authorize, only: [:create]
def create
@shout = current_user.shouts.new(params[:shout])
@shout.save
redirect_to dashboard_path
end
+
+ def show
+ @shout = Shout.find(params[:id])
+ end
end
View
6 app/controllers/users_controller.rb
@@ -0,0 +1,6 @@
+class UsersController < ApplicationController
+ def show
+ @user = User.find(params[:id])
+ @shouts = @user.shouts
+ end
+end
View
1 app/models/shout.rb
@@ -1,3 +1,4 @@
class Shout < ActiveRecord::Base
belongs_to :user
+ delegate :email, to: :user, prefix: true
end
View
2 app/views/dashboards/show.html.erb
@@ -4,3 +4,5 @@ Welcome <%= current_user.email %>
<%= form.text_field :body, placeholder: "Shout here" %>
<%= form.submit "Shout!" %>
<% end %>
+
+<%= render @shouts %>
View
5 app/views/shouts/_shout.html.erb
@@ -0,0 +1,5 @@
+<%= content_tag_for(:div, shout) do %>
+ <%= link_to shout.user_email, shout.user %>
+ <%= shout.body %>
+ <%= link_to time_ago_in_words(shout.created_at), shout %> ago
+<% end %>
View
1 app/views/shouts/show.html.erb
@@ -0,0 +1 @@
+<%= render @shout %>
View
2 app/views/users/show.html.erb
@@ -0,0 +1,2 @@
+<h1><%= @user.email %></h1>
+<%= render @shouts %>
View
3 config/routes.rb
@@ -1,5 +1,6 @@
Shouter::Application.routes.draw do
root to: "welcome#index"
resource :dashboard, only: [:show]
- resources :shouts, only: [:create]
+ resources :shouts, only: [:create, :show]
+ resources :users, only: [:show]
end

0 comments on commit ce099c4

Please sign in to comment.
Something went wrong with that request. Please try again.