Random Sequence

and their PHP equivalents.

Sponsored Links:

Site-Wide Global Variables in Ruby on Rails

For the sites built using PHP, it’s common practice to include a common config.php file which contains global variables accessible on every page, for example:

<?php
// config.php
$site_name = "Random Sequence";
$site_url = "http://www.randomsequence.com";
?>

To display these global variables in a view:

<?php echo $site_name; ?>
<?php echo $site_url; ?>

To replicate this functionality in Rails, you can define methods in the site-wide /app/helpers/application_helper.rb, for example:

Methods added to this helper will be available to all templates in the application.

module ApplicationHelper def site_name "Random Sequence" end

def site_url "http://www.randomsequence.com" end
end

To use these helpers in your view:

<%= site_name %>
<%= site_url %>

Sponsored Links: