Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Persist shouts.

  • Loading branch information...
commit dbabc3910f77fec9db825289a3b3aa64df9fd3d5 1 parent 621ad8d
@halogenandtoast halogenandtoast authored
View
3  app/controllers/dashboards_controller.rb
@@ -1,2 +1,5 @@
class DashboardsController < ApplicationController
+ def show
+ @shout = Shout.new
+ end
end
View
7 app/controllers/shouts_controller.rb
@@ -0,0 +1,7 @@
+class ShoutsController < ApplicationController
+ def create
+ shout = current_user.shouts.new(params[:shout])
+ shout.save
+ redirect_to dashboard_path, notice: "Shouted!"
+ end
+end
View
3  app/models/shout.rb
@@ -0,0 +1,3 @@
+class Shout < ActiveRecord::Base
+ belongs_to :user
+end
View
1  app/models/user.rb
@@ -1,3 +1,4 @@
class User < ActiveRecord::Base
include Clearance::User
+ has_many :shouts
end
View
6 app/views/dashboards/show.html.erb
@@ -1 +1,7 @@
<h1>Dashboard</h1>
+Welcome <%= current_user.email %> - <%= link_to "Sign out", sign_out_path, method: :delete %>
+
+<%= form_for(@shout) do |form| %>
+ <%= form.text_field :body, placeholder: "Shout here" %>
+ <%= form.submit "Shout!" %>
+<% end %>
View
3  config/routes.rb
@@ -1,4 +1,5 @@
Shouter::Application.routes.draw do
root to: "welcome#index"
- resource :dashboard
+ resource :dashboard, only: [:show]
+ resources :shouts, only: [:create]
end
View
11 db/migrate/20120312143222_create_shouts.rb
@@ -0,0 +1,11 @@
+class CreateShouts < ActiveRecord::Migration
+ def change
+ create_table :shouts do |t|
+ t.belongs_to :user
+ t.text :body
+
+ t.timestamps
+ end
+ add_index :shouts, :user_id
+ end
+end
View
11 db/schema.rb
@@ -11,7 +11,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120312134910) do
+ActiveRecord::Schema.define(:version => 20120312143222) do
+
+ create_table "shouts", :force => true do |t|
+ t.integer "user_id"
+ t.text "body"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "shouts", ["user_id"], :name => "index_shouts_on_user_id"
create_table "users", :force => true do |t|
t.string "email"
View
9 test/fixtures/shouts.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ user:
+ body: MyText
+
+two:
+ user:
+ body: MyText
View
7 test/unit/shout_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ShoutTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.