Permalink
Browse files

thru 10.3.2

  • Loading branch information...
1 parent e80fd1f commit 0e2bf8a9854914c01ce21f1458bc15b9d51f1fa9 @Milhouse committed Feb 27, 2012
@@ -0,0 +1,16 @@
+class MicropostsController < ApplicationController
+ before_filter :signed_in_user
+
+ def create
+ @micropost = current_user.microposts.build(params[:micropost])
+ if @micropost.save
+ flash[:success] = "Micropost created!"
+ redirect_to root_path
+ else
+ render 'static_pages/home'
+ end
+ end
+
+ def destroy
+ end
+end
@@ -1,5 +1,6 @@
class StaticPagesController < ApplicationController
def home
+ @micropost = current_user.microposts.build if signed_in?
end
def help
@@ -49,11 +49,6 @@ def destroy
end
private
-
- def signed_in_user
- store_location
- redirect_to signin_path, notice: "Please sign in." unless signed_in?
- end
def correct_user
@user = User.find(params[:id])
@@ -20,6 +20,13 @@ def current_user?(user)
user == current_user
end
+ def signed_in_user
+ unless signed_in?
+ store_location
+ redirect_to signin_path, notice: "Please sign in."
+ end
+ end
+
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
clear_return_to
@@ -1,10 +1,11 @@
-<% if @user.errors.any? %>
+<% if object.errors.any? %>
<div id="error_explanation">
- <h2><%= pluralize(@user.errors.count, "error") %>
- prohibited this user from being saved:</h2>
+ <h2><%= pluralize(object.errors.count, "error") %>
+ prohibited this <%= object.class.to_s.underscore.humanize.downcase %>
+ from being saved:</h2>
<p>There were problems with the following fields:</p>
<ul>
- <% @user.errors.full_messages.each do |msg| %>
+ <% object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@@ -0,0 +1,9 @@
+<%= form_for(@micropost) do |f| %>
+ <%= render 'shared/error_messages', object: f.object %>
+ <div class="field">
+ <%= f.text_area :content %>
+ </div>
+ <div class="actions">
+ <%= f.submit "Submit" %>
+ </div>
+<% end %>
@@ -0,0 +1,11 @@
+<div class="user_info">
+ <a href="<%= user_path(current_user) %>">
+ <%= gravatar_for(current_user, size: 30) %>
+ <span class="user_name">
+ <%= current_user.name %>
+ </span>
+ <span class="microposts">
+ <%= pluralize(current_user.microposts.count, "micropost") %>
+ </span>
+ </a>
+</div>
@@ -1,10 +1,24 @@
-<% provide(:title, 'Home') %>
-<h1>Sample App</h1>
+<<% provide(:title, 'Home') %>
+<% if signed_in? %>
+ <table class="front">
+ <tr>
+ <td class="main">
+ <h1 class="micropost">What's up?</h1>
+ <%= render 'shared/micropost_form' %>
+ </td>
+ <td class="sidebar round">
+ <%= render 'shared/user_info' %>
+ </td>
+ </tr>
+ </table>
+<% else %>
+ <h1>Sample App</h1>
-<p>
- This is the home page for the
- <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
- sample application.
-</p>
+ <p>
+ This is the home page for the
+ <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
+ sample application.
+ </p>
-<%= link_to "Sign up now!", signup_path, class: "signup_button round" %>
+ <%= link_to "Sign up now!", signup_path, class: "signup_button round" %>
+<% end %>
@@ -2,7 +2,7 @@
<h1>Edit user</h1>
<%= form_for(@user) do |f| %>
- <%= render 'shared/error_messages' %>
+ <%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
@@ -2,7 +2,7 @@
<h1>Sign up</h1>
<%= form_for(@user) do |f| %>
- <%= render 'shared/error_messages' %>
+ <%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
View
@@ -1,6 +1,7 @@
SampleApp::Application.routes.draw do
resources :users
resources :sessions, only: [:new, :create, :destroy]
+resources :microposts, only: [:create, :destroy]
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'

0 comments on commit 0e2bf8a

Please sign in to comment.