Tuesday, March 14, 2023
HomeRuby On RailsDesigning your public fixed web pages as sources in Ruby on Bed...

Designing your public fixed web pages as sources in Ruby on Bed Rails

So we examined 2 significant means currently of developing public (basically) fixed web pages:

  1. strength drop your HTML right into the app/assets/public
  2. have custom-made activities in something like a PublicPagesController/ StaticPagesController

Currently I intended to consider one more technique.

Initially, I saw this in David Copeland’s publication Lasting Internet Growth with Ruby on Bed rails.

He recommends modeling public fixed web pages as sources, like you would certainly perform with the vibrant web pages, to maintain points constant as well as much more lasting. Besides, the idea of guide as well as of Bed rails is to maintain it remainder as well as instead produce sources than custom-made courses.

So, a really straightforward instance would certainly be for you to have a source: privacy_policy, just[:show] The nasty point with that said is that while you are recommending a solitary source right here, Bed rails controllers are not clever adequate to recognize it, so you would certainly still require to call it from a PrivacyPoliciesController However you most likely have simply 1 plan

While we might cope with that or function around it, we might still wind up with a great deal of things as well as lots of sources that would certainly trash our application, like if we had a source for every public documents web page or individual abdominal muscle experiment web page that advertising is tossing at us.

So, in these instances, you could still wish to select our custom-made courses technique as well as namespace those pesky advertising as well as doc web pages:

 # routes.rb
namespace: advertising do
obtain: ab_test_feature1.
# ...
obtain: experiment_99.

What obtained me motivated by this technique is that I guided myself right into a far better kind of reasoning. I went from having a public web pages controller where I would certainly include my public web pages as custom-made courses:

 course PublicPagesController < < ApplicationController.
def house.
# TODO: Produce a touchdown web page for the origin path.

def major_systems.
@major_systems = MajorSystem.for _ public_view. preload(: secures).

# ... even more custom-made courses ...

To a source each:

 course Public:: HomeController < < ApplicationController.
def program.
# We'll reveal the sight right here.

course Public:: MajorSystemsController < < ApplicationController.
def index.
@major_systems = MajorSystem.original.language( major_systems_params[:language_iso]).

def program.
@major_system = MajorSystem.find( major_system_params[:id]).


def major_systems_params.
params.permit(: language_iso).

def major_system_params.
params.permit(: id).

Simply by considering sources, the general public web pages ended up being even more of a complete display of my attribute. Prior to that, I was attempting to pack whatever right into one path ( PublicPagesController #major _ systems) and after that in some way dynamically select which system to present by means of JavaScript or Turbo. Now on among the general public attribute web pages, the customers can see a listing of functions in their recommended language (picked by means of dropdown). It minimized the variety of dropdowns on the web page from 2 to 1, hence streamlining the UX.

There's additionally an information web page that reveals a provided source in much more information that was simple to incorporate in the Bed rails method utilizing Bed rails partials as well as co.

You'll additionally see that my public "fixed" web pages are not totally fixed, this is due to the fact that I such as to display some capability in there with real information, that makes them possibly instead public vibrant web pages However on the various other hand, the information that I'm revealing is relatively fixed, it simply occurs to find from the data source;-RRB-)

Anyhow, that's type of a harsh overview of the entire public fixed web pages as a source technique.

I do not believe modeling your public web pages as sources is extensively made use of or recorded anywhere, however I simulated what it performed in completion to my reasoning, the code, as well as the result for the individual. Win-win-win.


Most Popular

Recent Comments