diff --git a/Gemfile b/Gemfile index 348297f..091dbde 100644 --- a/Gemfile +++ b/Gemfile @@ -15,3 +15,5 @@ gem 'spring', group: :development gem 'omniauth-google-oauth2', '~> 0.2.5' gem 'bootstrap-sass', '~> 3.2.0.2' + +gem 'rb-readline' diff --git a/Gemfile.lock b/Gemfile.lock index 94ebbb7..0e7e2fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,6 +96,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.3.2) + rb-readline (0.5.1) rdoc (4.1.2) json (~> 1.4) sass (3.2.19) @@ -139,6 +140,7 @@ DEPENDENCIES jquery-rails omniauth-google-oauth2 (~> 0.2.5) rails (= 4.1.6) + rb-readline sass-rails (~> 4.0.3) sdoc (~> 0.4.0) spring diff --git a/app/assets/javascripts/user.js.coffee b/app/assets/javascripts/user.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/user.js.coffee @@ -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://coffeescript.org/ diff --git a/app/assets/stylesheets/user.css.scss b/app/assets/stylesheets/user.css.scss new file mode 100644 index 0000000..c47a13e --- /dev/null +++ b/app/assets/stylesheets/user.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the User controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/friendships_controller.rb b/app/controllers/friendships_controller.rb index 7615b1e..e0e6ef8 100644 --- a/app/controllers/friendships_controller.rb +++ b/app/controllers/friendships_controller.rb @@ -1,54 +1,29 @@ class FriendshipsController < ApplicationController before_action :require_login - before_action :set_friendship, only: [:show, :destroy] def index @friendships = Friendship.all end - def show - end - - def new - @friendship = Friendship.new - end - def create - @friendship = Friendship.new(friendship_params) + @friendship = current_user.friendships.build(friendship_params) - respond_to do |format| - if @friendship.save - format.html { - redirect_to @friendship, - notice: 'Friendship was successfully created.' - } - format.json { render :show, status: :created, location: @friendship } - else - format.html { render :new } - format.json { - render json: @friendship.errors, status: :unprocessable_entity - } - end + if @friendship.save + flash[:notice] = 'Added friend.' + redirect_to root_url + else + flash[:notice] = 'Unable to add friend.' + redirect_to root_url end end def destroy - @friendship.destroy - respond_to do |format| - format.html { - redirect_to friendships_url, - notice: 'Friendship was successfully destroyed.' - } - format.json { head :no_content } - end end private - def set_friendship - @friendship = Friendship.find(params[:id]) - end - def friendship_params - params[:friendship] - end + def friendship_params + # why not namespaced + params.permit(:friend_id) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..bbab75d --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,8 @@ +class UsersController < ApplicationController + def index + @users = User.all + end + + def show + end +end diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb new file mode 100644 index 0000000..0147c3f --- /dev/null +++ b/app/helpers/user_helper.rb @@ -0,0 +1,2 @@ +module UserHelper +end diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 0000000..1eb3b1b --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,24 @@ +

User List

+ + + + + + + + + + + + <% @users.each do |user| %> + + + + + + +<% end %> + +
NameCreatedUpdatedActions
<%= link_to user.name, user %><%= user.created_at %><%= user.updated_at %> + <%= link_to '+', friendships_path(:friend_id => user), :method => :post %> +
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000..301bd6e --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,2 @@ +

User#show

+

Find me in app/views/user/show.html.erb

diff --git a/config/routes.rb b/config/routes.rb index 7e57d2b..b15e310 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,8 +4,9 @@ Rails.application.routes.draw do get 'logout', to: 'sessions#destroy', as: 'logout' resources :home, only: [ :show ] - resources :friendships, only: [ :index, :show, :create, :new, :destroy ] + resources :friendships, only: [ :index, :show, :create, :destroy ] resources :sessions, only: [ :create, :destroy ] + resources :users, only: [ :index, :show ] root to: 'home#show' end diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb new file mode 100644 index 0000000..ed2b57e --- /dev/null +++ b/test/controllers/user_controller_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class UserControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end + + test "should get show" do + get :show + assert_response :success + end + +end diff --git a/test/helpers/user_helper_test.rb b/test/helpers/user_helper_test.rb new file mode 100644 index 0000000..ad44a53 --- /dev/null +++ b/test/helpers/user_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class UserHelperTest < ActionView::TestCase +end