vendredi 30 septembre 2016

Ruby / Rails - Devise - before_action :authenticate_user! blocking else statement display

I would like to utilize my "plans" into a separate partial or perhaps a new file/location altogether. This page or partial should be accessed from a button on the landing page. Currently, my "plans" html is set to display conditionally on my home page if a user is not signed in. Due to the "before_action :authenticate_user!" I have on the home page, viewing the "else" (which contains the plans) can not be viewed. Should I separate the plans onto a separate page and remove the conditional statement? Or should I partial it out and render the view in my else statement?

Do I need to provide additional info?

Am I using correct terminology?


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 %>


pages_controller.rb

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

Aucun commentaire:

Enregistrer un commentaire