Permalink
Browse files

just in case

  • Loading branch information...
javierqs committed Feb 2, 2012
1 parent a4422f4 commit a3e88129fdd9bef589cf0c3590bb76f668011d1a
Showing with 490 additions and 243 deletions.
  1. +4 −1 Gemfile
  2. +16 −0 Gemfile.lock
  3. +1 −0 app/assets/javascripts/application.js
  4. +22 −0 app/assets/javascripts/bootstrap.js.coffee
  5. +3 −0 app/assets/javascripts/chats.js.coffee
  6. +3 −0 app/assets/javascripts/sessions.js.coffee
  7. +1 −0 app/assets/stylesheets/application.css
  8. +5 −0 app/assets/stylesheets/bootstrap.css.less
  9. +3 −0 app/assets/stylesheets/chats.css.scss
  10. +56 −0 app/assets/stylesheets/scaffolds.css.scss
  11. +3 −0 app/assets/stylesheets/sessions.css.scss
  12. +8 −0 app/controllers/application_controller.rb
  13. +83 −0 app/controllers/chats_controller.rb
  14. +15 −0 app/controllers/sessions_controller.rb
  15. +2 −0 app/helpers/chats_helper.rb
  16. +2 −0 app/helpers/sessions_helper.rb
  17. +2 −0 app/models/chat.rb
  18. +11 −0 app/models/user.rb
  19. +25 −0 app/views/chats/_form.html.erb
  20. +6 −0 app/views/chats/edit.html.erb
  21. +25 −0 app/views/chats/index.html.erb
  22. +5 −0 app/views/chats/new.html.erb
  23. +15 −0 app/views/chats/show.html.erb
  24. +12 −0 app/views/layouts/application.html.erb
  25. +3 −0 config/initializers/omniauth.rb
  26. +9 −1 config/routes.rb
  27. +11 −0 db/migrate/20120202015742_create_users.rb
  28. +10 −0 db/migrate/20120202021059_create_chats.rb
  29. +31 −0 db/schema.rb
  30. +0 −241 public/index.html
  31. +9 −0 test/fixtures/chats.yml
  32. +11 −0 test/fixtures/users.yml
  33. +49 −0 test/functional/chats_controller_test.rb
  34. +7 −0 test/functional/sessions_controller_test.rb
  35. +7 −0 test/unit/chat_test.rb
  36. +4 −0 test/unit/helpers/chats_helper_test.rb
  37. +4 −0 test/unit/helpers/sessions_helper_test.rb
  38. +7 −0 test/unit/user_test.rb
View
@@ -40,4 +40,7 @@ gem 'jquery-rails'
gem 'simple_form'
gem 'omniauth-openid'
gem 'omniauth-twitter'
-gem 'omniauth-facebook'
+gem 'omniauth-facebook'
+
+#does it works with 3.2.1?
+gem 'twitter-bootstrap-rails', :group => :assets
View
@@ -38,6 +38,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
+ commonjs (0.2.0)
+ therubyracer (~> 0.9.9)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
@@ -53,6 +55,13 @@ GEM
railties (>= 3.2.0.beta, < 5.0)
thor (~> 0.14)
json (1.6.5)
+ less (2.0.9)
+ commonjs (~> 0.2.0)
+ therubyracer (~> 0.9.9)
+ less-rails (2.1.5)
+ actionpack (>= 3.1)
+ less (~> 2.0.7)
+ libv8 (3.3.10.4)
mail (2.4.1)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -123,11 +132,17 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
+ therubyracer (0.9.9)
+ libv8 (~> 3.3.10)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
+ twitter-bootstrap-rails (2.0)
+ actionpack (>= 3.2.1)
+ less-rails (~> 2.1.2)
+ railties (>= 3.2.1)
tzinfo (0.3.31)
uglifier (1.2.3)
execjs (>= 0.3.0)
@@ -146,4 +161,5 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
simple_form
sqlite3
+ twitter-bootstrap-rails
uglifier (>= 1.0.3)
@@ -12,4 +12,5 @@
//
//= require jquery
//= require jquery_ujs
+//= require twitter/bootstrap
//= require_tree .
@@ -0,0 +1,22 @@
+$ ->
+ $(".alert-message").alert()
+$ ->
+ $(".tabs").button()
+$ ->
+ $(".carousel").carousel()
+$ ->
+ $(".collapse").collapse()
+$ ->
+ $(".dropdown-toggle").dropdown()
+$ ->
+ $(".modal").modal
+$ ->
+ $("a[rel]").popover
+$ ->
+ $(".navbar").scrollspy()
+$ ->
+ $(".tab").tab "show"
+$ ->
+ $(".tooltip").tooltip
+$ ->
+ $(".typeahead").typeahead()
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -9,5 +9,6 @@
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
+ *= require twitter/bootstrap
*= require_tree .
*/
@@ -0,0 +1,5 @@
+@import "twitter/bootstrap";
+
+// Baseline grid
+@basefont: 13px;
+@baseline: 18px;
@@ -0,0 +1,3 @@
+// Place all the styles related to the chats controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
@@ -0,0 +1,3 @@
+// Place all the styles related to the sessions controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -1,3 +1,11 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
+ helper_method :current_user
+
+ private
+
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
end
@@ -0,0 +1,83 @@
+class ChatsController < ApplicationController
+ # GET /chats
+ # GET /chats.json
+ def index
+ @chats = Chat.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @chats }
+ end
+ end
+
+ # GET /chats/1
+ # GET /chats/1.json
+ def show
+ @chat = Chat.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @chat }
+ end
+ end
+
+ # GET /chats/new
+ # GET /chats/new.json
+ def new
+ @chat = Chat.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @chat }
+ end
+ end
+
+ # GET /chats/1/edit
+ def edit
+ @chat = Chat.find(params[:id])
+ end
+
+ # POST /chats
+ # POST /chats.json
+ def create
+ @chat = Chat.new(params[:chat])
+
+ respond_to do |format|
+ if @chat.save
+ format.html { redirect_to @chat, notice: 'Chat was successfully created.' }
+ format.json { render json: @chat, status: :created, location: @chat }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @chat.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /chats/1
+ # PUT /chats/1.json
+ def update
+ @chat = Chat.find(params[:id])
+
+ respond_to do |format|
+ if @chat.update_attributes(params[:chat])
+ format.html { redirect_to @chat, notice: 'Chat was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @chat.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /chats/1
+ # DELETE /chats/1.json
+ def destroy
+ @chat = Chat.find(params[:id])
+ @chat.destroy
+
+ respond_to do |format|
+ format.html { redirect_to chats_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -0,0 +1,15 @@
+class SessionsController < ApplicationController
+
+ def create
+ auth = request.env["omniauth.auth"]
+ user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
+ session[:user_id] = user.id
+ redirect_to root_url, :notice => "Signed in!"
+ end
+
+ def destroy
+ session[:user_id] = nil
+ redirect_to root_url, :notice => "Signed out!"
+ end
+
+end
@@ -0,0 +1,2 @@
+module ChatsHelper
+end
@@ -0,0 +1,2 @@
+module SessionsHelper
+end
View
@@ -0,0 +1,2 @@
+class Chat < ActiveRecord::Base
+end
View
@@ -0,0 +1,11 @@
+class User < ActiveRecord::Base
+
+ def self.create_with_omniauth(auth)
+ create! do |user|
+ user.provider = auth["provider"]
+ user.uid = auth["uid"]
+ user.name = auth["info"]["name"]
+ end
+ end
+
+end
@@ -0,0 +1,25 @@
+<%= form_for(@chat) do |f| %>
+ <% if @chat.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@chat.errors.count, "error") %> prohibited this chat from being saved:</h2>
+
+ <ul>
+ <% @chat.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :user_name %><br />
+ <%= f.text_field :user_name %>
+ </div>
+ <div class="field">
+ <%= f.label :content %><br />
+ <%= f.text_area :content %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing chat</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @chat %> |
+<%= link_to 'Back', chats_path %>
@@ -0,0 +1,25 @@
+<h1>Listing chats</h1>
+
+<table>
+ <tr>
+ <th>User name</th>
+ <th>Content</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @chats.each do |chat| %>
+ <tr>
+ <td><%= chat.user_name %></td>
+ <td><%= chat.content %></td>
+ <td><%= link_to 'Show', chat %></td>
+ <td><%= link_to 'Edit', edit_chat_path(chat) %></td>
+ <td><%= link_to 'Destroy', chat, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Chat', new_chat_path %>
@@ -0,0 +1,5 @@
+<h1>New chat</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', chats_path %>
@@ -0,0 +1,15 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>User name:</b>
+ <%= @chat.user_name %>
+</p>
+
+<p>
+ <b>Content:</b>
+ <%= @chat.content %>
+</p>
+
+
+<%= link_to 'Edit', edit_chat_path(@chat) %> |
+<%= link_to 'Back', chats_path %>
Oops, something went wrong.

0 comments on commit a3e8812

Please sign in to comment.