Skip to content

Commit

Permalink
Persist shouts.
Browse files Browse the repository at this point in the history
  • Loading branch information
halogenandtoast committed Mar 12, 2012
1 parent 621ad8d commit dbabc39
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/controllers/dashboards_controller.rb
@@ -1,2 +1,5 @@
class DashboardsController < ApplicationController
def show
@shout = Shout.new
end
end
7 changes: 7 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions app/models/shout.rb
@@ -0,0 +1,3 @@
class Shout < ActiveRecord::Base
belongs_to :user
end
1 change: 1 addition & 0 deletions app/models/user.rb
@@ -1,3 +1,4 @@
class User < ActiveRecord::Base
include Clearance::User
has_many :shouts
end
6 changes: 6 additions & 0 deletions 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 %>
3 changes: 2 additions & 1 deletion 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
11 changes: 11 additions & 0 deletions 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
11 changes: 10 additions & 1 deletion db/schema.rb
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions test/unit/shout_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class ShoutTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit dbabc39

Please sign in to comment.