Skip to content

Commit

Permalink
Merge pull request #16 from josefzacek/layout-update-basic-messages-i…
Browse files Browse the repository at this point in the history
…mplementation

Layout update basic messages implementation
  • Loading branch information
josefzacek authored Aug 14, 2016
2 parents 8a437d8 + 727decf commit 7bc6c81
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 13 deletions.
8 changes: 8 additions & 0 deletions app/assets/javascripts/chatrooms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$(document).on('turbolinks:load', function() {
$('#new_message').on('keypress', function(e) {
if(e && e.keyCode == 13){
e.preventDefault();
$(this).submit();
}
});
});
File renamed without changes.
10 changes: 10 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
@import "bootstrap-sprockets";
@import "bootstrap";
@import 'devise_flash_messages';

.container-fluid.content-container {
padding-top: 70px;
}

.sidebar-fixed-position {
position: fixed;
top: 70;
left: 0;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/messages.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Messages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
1 change: 1 addition & 0 deletions app/controllers/chatrooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def index
# GET /chatrooms/1
# GET /chatrooms/1.json
def show
@messages = @chatroom.messages.order(created_at: :desc).limit(100).reverse
end

# GET /chatrooms/new
Expand Down
21 changes: 21 additions & 0 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class MessagesController < ApplicationController
before_action :authenticate_user!
before_action :set_chatroom

def create
message = @chatroom.messages.new(message_params)
message.user = current_user
message.save
redirect_to @chatroom
end

private

def set_chatroom
@chatroom = Chatroom.find(params[:chatroom_id])
end

def message_params
params.require(:message).permit(:body)
end
end
2 changes: 2 additions & 0 deletions app/helpers/messages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MessagesHelper
end
7 changes: 0 additions & 7 deletions app/views/chatrooms/show.html.erb

This file was deleted.

14 changes: 14 additions & 0 deletions app/views/chatrooms/show.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
p
strong Chatroom name:
= @chatroom.name


div data-behavior='messages'
- @messages.each do |message|
div
strong = message.user.username
|:
= message.body

= form_for [@chatroom, Message.new] do |f|
= f.text_area :body, rows: 1, autofocus: true, class: 'form-control'
2 changes: 1 addition & 1 deletion app/views/layouts/_header_navigation.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nav.navbar.navbar-default.navbar-static-top
nav.navbar.navbar-default.navbar-fixed-top
.container-fluid
.navbar-header
button.navbar-toggle.collapsed type='button' data-toggle='collapse' data-target='#navbar' aria-expanded='false' aria-controls='navbar'
Expand Down
11 changes: 6 additions & 5 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ html lang="en"

= render "layouts/header_navigation"

.container-fluid
.container-fluid.content-container

= render 'layouts/flash_messages'

.row
.col-sm-2
.col-sm-3.sidebar-fixed-position
- if user_signed_in?
h5 Chatrooms
ul
ul.nav.nav-pills.nav-stacked
- current_user.chatrooms.each do |chatroom|
li = link_to chatroom.name, '#'
.col-sm-10
li = link_to chatroom.name, chatroom

.col-sm-9.col-sm-offset-3
= yield

hr
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

resources :chatrooms do
resource :chatroom_users
resources :messages
end

root to: 'chatrooms#index'
Expand Down

0 comments on commit 7bc6c81

Please sign in to comment.