🖼️Customize the views

How to change the views using LightningRails partials/components

Using Tailwind Front-end Components in Your Ruby on Rails Application

In our Ruby on Rails application, we utilize Tailwind CSS for styling, complemented by components from the DaisyUI library. You will find the custom Tailwind components organized in the views > components folder.

Using DaisyUI Components

We use DaisyUI to enhance our Tailwind components with pre-designed UI elements. DaisyUI provides various components that you can easily integrate into your application, allowing for rapid and responsive UI design.

You can explore the full range of DaisyUI components on their website: DaisyUI.

Feel free to check out their library and incorporate any components that fit your design needs into our application!


Rendering Tailwind Components included by default in Lightning Rails

To include Tailwind components in your views, simply use the render ERB tag. This makes it super easy to integrate components throughout your application.

How easy is it? The entire LightningRails home page is built with just 7 lines of code (already included in the boilerplate) 🤯:

# views/home.html.erb
<%= render "components/hero" %>
<%= render "components/featured_on" %>
<%= render "components/text_image" %>
<%= render "components/feature_tabs" %>
<%= render "components/price_cards" %>
<%= render "components/faq" %>
<%= render "components/cta_horizontal" %>

(Optional) - Passing Instance Variables to Components

If you have instance variables in your controller and want to pass them to a button component, here's how you can do it:

  1. Pass any variable to the component:

    When rendering the button component in your view:

    <%= render 'components/button', locals: { label: @button_label, color: @button_color } %>
  2. Access the variables in your component:

    In your _button.html.erb partial, you can now use the label and color variables to customize the button:

    <button class="<%= color %> text-white font-bold py-2 px-4 rounded">
      <%= label %>
    </button>

Last updated