2016-07-08 5 views
0

Michael Hartl's Railsチュートリアルの指針に従っている間、私はblogappに取り組んでいます。私のログインページは、1つのブランチで動作し、他のブランチで動作しないのはなぜですか?

私が1つの支店(非マスター)にいるとき、私はそのページをリクエストするとログインページが正しく挿入されます。しかし、私が別の支店(非マスター)にいると、次のエラーが発生します。

ブランチを誤ってマージしましたか?

users_controller.rb

class UsersController < ApplicationController 
    before_action :logged_in_user, only: [:index, :edit, :update] 
    before_action :correct_user, only: [:edit, :update] 

    def show 
    @user = User.find(params[:id]) 
    end 

    def new 
    @user = User.new 
    end 

    def create 
    @user = User.new(user_params) 
    if @user.save 
     log_in @user 
     flash[:success] = "Welcome to the Sample App!" 
     redirect_to @user 
    else 
     render 'new' 
    end 
    end 

    def edit 
    @user = User.find(params[:id]) 
    end 
    def index 
    @users = User.all 
    end 
    def update 
    @user = User.find(params[:id]) 
    if @user.update_attributes(user_params) 
     # Handle a successful update. 
    else 
     render 'edit' 
    end 
    end 

    private 

    def user_params 
     params.require(:user).permit(:name, :email, :password, 
            :password_confirmation) 
    end 
    # Before filters 

    # Confirms a logged-in user. 
    def logged_in_user 
     unless logged_in? 
     store_location 
     flash[:danger] = "Please log in." 
     redirect_to login_url 
     end 
    end 

    # Confirms the correct user. 
    def correct_user 
     @user = User.find(params[:id]) 
     redirect_to(root_url) unless current_user?(@user) 
    end 
end 

routes.rb 
    Rails.application.routes.draw do 
    get 'users/new' 

    get 'blog_pages/home' 

    get 'about' => 'blog_pages#about' 

    get 'goodstuff' => 'blog_pages#goodstuff' 

    get 'serenity' => 'blog_pages#serenity' 

    get 'contact' => 'blog_pages#contact' 

    get 'signup' => 'users#new' 
    resources :users 

    # The priority is based upon order of creation: first created -> highest priority. 
    # See how all your routes lay out with "rake routes". 

    # You can have the root of your site routed with "root" 
root 'application#Blog' 

    # Example of regular route: 
    # get 'products/:id' => 'catalog#view' 

    # Example of named route that can be invoked with purchase_url(id: product.id) 
    # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 

    # Example resource route (maps HTTP verbs to controller actions automatically): 
    # resources :products 

    # Example resource route with options: 
    # resources :products do 
    #  member do 
    #  get 'short' 
    #  post 'toggle' 
    #  end 
    # 
    #  collection do 
    #  get 'sold' 
    #  end 
    # end 

    # Example resource route with sub-resources: 
    # resources :products do 
    #  resources :comments, :sales 
    #  resource :seller 
    # end 

    # Example resource route with more complex sub-resources: 
    # resources :products do 
    #  resources :comments 
    #  resources :sales do 
    #  get 'recent', on: :collection 
    #  end 
    # end 

    # Example resource route with concerns: 
    # concern :toggleable do 
    #  post 'toggle' 
    # end 
    # resources :posts, concerns: :toggleable 
    # resources :photos, concerns: :toggleable 

    # Example resource route within a namespace: 
    # namespace :admin do 
    #  # Directs /admin/products/* to Admin::ProductsController 
    #  # (app/controllers/admin/products_controller.rb) 
    #  resources :products 
    # end 
end 
+2

エラーメッセージが表示されません。 – user1875195

+0

は、ルートとユーザーのコントローラファイルを追加したばかりです。エラーは単純に次のように表示されます。第2の非マスターブランチの訪問/ログイン時には「申し訳ありませんが何かが間違っています」 –

答えて

0

あなたの枝をマージすることができなかったように見えるので、あなたのルートには/ログインルートはありません。

+0

そのように見えます。ありがとう@ dj2 –

関連する問題