2016-09-30 7 views
0

私は自分の "計画"を部分的に、あるいは新しいファイル/場所に利用したいと思います。このページまたは部分は、リンク先ページのボタンからアクセスする必要があります。現在、私の "plans" htmlは、ユーザーがサインインしていない場合、私のホームページに条件付きで表示するように設定されています。 "before_action:authenticate_user!"私はホームページに「else」(計画を含む)を表示することはできません。プランを別のページに分けて条件文を削除する必要がありますか?または、私はそれを部分的に取り除き、私のelseステートメントでビューをレンダリングする必要がありますか?Ruby/Rails - Devise - before_action:authenticate_user!ブロッキングelseステートメント表示

追加情報を提供する必要がありますか?

正しい用語を使用していますか?


home.html.erb

<div class="row"> 
<% if user_signed_in? %> 

    <%= render 'users/home' %> 

<% else %> 

<!--Plans--> 
<div class="row"> 
    <div class="col-lg-3"> 
     <div class="well text-center"> 

      <!--Plan #1--> 
      <%= link_to "REGISTER", new_user_registration_path(plan: @contributor_plan.id), class:'btn btn-info btn-block' %> 

      <!--Plan #2--> 
      <%= link_to "REGISTER", new_user_registration_path(plan: @elitecontributor_plan.id), class:'btn btn-warning btn-block' %> 

      <!--Plan #3--> 
      <%= link_to "REGISTER", new_user_registration_path(plan: @technician_plan.id), class:'btn btn-info btn-block' %> 

      <!--Plan #4--> 
      <%= link_to "REGISTER", new_user_registration_path(plan: @elitetechnician_plan.id), class:'btn btn-info btn-block' %> 

      </div> 
     </div> 
    </div> 

<% end %> 

あなたは2つの別々のルートルート、認証されたユーザーのための1、および認証された非ための1つを持つことができます

class PagesController < ApplicationController 
before_action :authenticate_user!, except: [:landing, :plans] 

def landing 

end 

def plans 
end 

def home 
    @contributor_plan = Plan.find(1) 
    @elitecontributor_plan = Plan.find(2) 
    @technician_plan = Plan.find(3) 
    @elitetechnician_plan = Plan.find(4) 
    @center_plan = Plan.find(5) 
    @elitecenter_plan = Plan.find(6) 
    @affair_plan = Plan.find(7) 
    @eliteaffair_plan = Plan.find(8) 
end 

答えて

0

pages_controller.rbユーザー。あなたはDeviseを使っていると思いますか?

設定/ルート:

authenticated do 
    root :to => 'pages#home', as: :authenticated 
end 

root :to => 'pages#plans' 

はい、あなたは私が推薦され、それ自身のリソースへのプランを分けることができ、あなたの質問の後半部分に答えるために。

そして、それはこのようなものになるだろう:

設定/ルート:

authenticated do 
    root :to => 'home#dashboard', as: :authenticated 
end 

root :to => 'plans#index' 
関連する問題