2016-09-30 2 views
0

"Plan"을 별도의 부분 파일 또는 새로운 파일/위치로 활용하고 싶습니다. 이 페이지 또는 부분은 방문 페이지의 버튼에서 액세스해야합니다. 현재 "plans"html은 사용자가 로그인하지 않은 경우 내 홈페이지에 조건부로 표시되도록 설정되어 있습니다. "before_action : authenticate_user!" 나는 홈페이지에서 "else"(계획이 포함되어 있음)를 볼 수 없습니다. 계획을 별도의 페이지로 분리하고 조건문을 제거해야합니까? 아니면 내가 부분적으로 그것을 내외부 성명에서 렌더링해야합니까?Ruby/Rails - Devise - before_action : authenticate_user! blocking else statement display

추가 정보를 제공해야합니까?

올바른 용어를 사용하고 있습니까?


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 개 개의 별도 경로 경로, 인증 된 사용자에 대한, 그리고 인증이 아닌 하나를 가질 수

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' 

는 그 다음이 같은 것