309 lines
11 KiB
HTML
309 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
! Excerpted from "Agile Web Development with Rails",
|
|
! published by The Pragmatic Bookshelf.
|
|
! Copyrights apply to this code. It may not be used to create training material,
|
|
! courses, books, articles, and the like. Contact us if you are in doubt.
|
|
! We make no guarantees that this code is fit for any purpose.
|
|
! Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
|
|
-->
|
|
|
|
<html>
|
|
<head>
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
|
|
<title>class ApplicationController - Rails Application Documentation</title>
|
|
|
|
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
|
|
|
|
<script type="text/javascript">
|
|
var rdoc_rel_prefix = "./";
|
|
</script>
|
|
|
|
<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
|
|
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
|
|
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
|
|
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
|
|
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
|
|
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
|
|
|
|
|
|
<body id="top" class="class">
|
|
<nav id="metadata">
|
|
<nav id="home-section" class="section">
|
|
<h3 class="section-header">
|
|
<a href="./index.html">Home</a>
|
|
<a href="./table_of_contents.html#classes">Classes</a>
|
|
<a href="./table_of_contents.html#methods">Methods</a>
|
|
</h3>
|
|
</nav>
|
|
|
|
|
|
<nav id="search-section" class="section project-section" class="initially-hidden">
|
|
<form action="#" method="get" accept-charset="utf-8">
|
|
<h3 class="section-header">
|
|
<input type="text" name="search" placeholder="Search" id="search-field"
|
|
title="Type to search, Up and Down to navigate, Enter to load">
|
|
</h3>
|
|
</form>
|
|
|
|
<ul id="search-results" class="initially-hidden"></ul>
|
|
</nav>
|
|
|
|
|
|
<div id="file-metadata">
|
|
<nav id="file-list-section" class="section">
|
|
<h3 class="section-header">Defined In</h3>
|
|
<ul>
|
|
<li>app/controllers/application_controller.rb
|
|
</ul>
|
|
</nav>
|
|
|
|
|
|
</div>
|
|
|
|
<div id="class-metadata">
|
|
|
|
<nav id="parent-class-section" class="section">
|
|
<h3 class="section-header">Parent</h3>
|
|
|
|
<p class="link">ActionController::Base
|
|
|
|
</nav>
|
|
|
|
|
|
<!-- Method Quickref -->
|
|
<nav id="method-list-section" class="section">
|
|
<h3 class="section-header">Methods</h3>
|
|
|
|
<ul class="link-list">
|
|
|
|
<li><a href="#method-i-authorize">#authorize</a>
|
|
|
|
<li><a href="#method-i-default_url_options">#default_url_options</a>
|
|
|
|
<li><a href="#method-i-set_i18n_locale_from_params">#set_i18n_locale_from_params</a>
|
|
|
|
</ul>
|
|
</nav>
|
|
|
|
</div>
|
|
|
|
<div id="project-metadata">
|
|
<nav id="fileindex-section" class="section project-section">
|
|
<h3 class="section-header">Pages</h3>
|
|
|
|
<ul>
|
|
|
|
<li class="file"><a href="./README_rdoc.html">README</a>
|
|
|
|
</ul>
|
|
</nav>
|
|
|
|
<nav id="classindex-section" class="section project-section">
|
|
<h3 class="section-header">Class and Module Index</h3>
|
|
|
|
<ul class="link-list">
|
|
|
|
<li><a href="./AdminController.html">AdminController</a>
|
|
|
|
<li><a href="./AdminHelper.html">AdminHelper</a>
|
|
|
|
<li><a href="./ApplicationController.html">ApplicationController</a>
|
|
|
|
<li><a href="./ApplicationHelper.html">ApplicationHelper</a>
|
|
|
|
<li><a href="./Cart.html">Cart</a>
|
|
|
|
<li><a href="./CartsController.html">CartsController</a>
|
|
|
|
<li><a href="./CartsHelper.html">CartsHelper</a>
|
|
|
|
<li><a href="./CurrentCart.html">CurrentCart</a>
|
|
|
|
<li><a href="./LineItem.html">LineItem</a>
|
|
|
|
<li><a href="./LineItemsController.html">LineItemsController</a>
|
|
|
|
<li><a href="./LineItemsHelper.html">LineItemsHelper</a>
|
|
|
|
<li><a href="./Order.html">Order</a>
|
|
|
|
<li><a href="./OrderNotifier.html">OrderNotifier</a>
|
|
|
|
<li><a href="./OrdersController.html">OrdersController</a>
|
|
|
|
<li><a href="./OrdersHelper.html">OrdersHelper</a>
|
|
|
|
<li><a href="./Product.html">Product</a>
|
|
|
|
<li><a href="./ProductsController.html">ProductsController</a>
|
|
|
|
<li><a href="./ProductsHelper.html">ProductsHelper</a>
|
|
|
|
<li><a href="./SessionsController.html">SessionsController</a>
|
|
|
|
<li><a href="./SessionsHelper.html">SessionsHelper</a>
|
|
|
|
<li><a href="./StoreController.html">StoreController</a>
|
|
|
|
<li><a href="./StoreHelper.html">StoreHelper</a>
|
|
|
|
<li><a href="./User.html">User</a>
|
|
|
|
<li><a href="./UsersController.html">UsersController</a>
|
|
|
|
<li><a href="./UsersHelper.html">UsersHelper</a>
|
|
|
|
</ul>
|
|
</nav>
|
|
|
|
</div>
|
|
</nav>
|
|
|
|
<div id="documentation">
|
|
<h1 class="class">class ApplicationController</h1>
|
|
|
|
<div id="description" class="description">
|
|
|
|
<p>START:i18n</p>
|
|
|
|
</div><!-- description -->
|
|
|
|
|
|
|
|
|
|
<section id="5Buntitled-5D" class="documentation-section">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Methods -->
|
|
|
|
<section id="protected-instance-5Buntitled-5D-method-details" class="method-section section">
|
|
<h3 class="section-header">Protected Instance Methods</h3>
|
|
|
|
|
|
<div id="method-i-authorize" class="method-detail ">
|
|
|
|
<div class="method-heading">
|
|
<span class="method-name">authorize</span><span
|
|
class="method-args">()</span>
|
|
<span class="method-click-advice">click to toggle source</span>
|
|
</div>
|
|
|
|
|
|
<div class="method-description">
|
|
|
|
<p>END:i18n</p>
|
|
|
|
|
|
|
|
<div class="method-source-code" id="authorize-source">
|
|
<pre><span class="ruby-comment"># File app/controllers/application_controller.rb, line 19</span>
|
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">authorize</span>
|
|
<span class="ruby-keyword">if</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">format</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Mime</span><span class="ruby-operator">::</span><span class="ruby-constant">HTML</span>
|
|
<span class="ruby-keyword">unless</span> <span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by</span>(<span class="ruby-identifier">id</span><span class="ruby-operator">:</span> <span class="ruby-identifier">session</span>[<span class="ruby-value">:user_id</span>])
|
|
<span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">login_url</span>, <span class="ruby-identifier">notice</span><span class="ruby-operator">:</span> <span class="ruby-string">"Please log in"</span>
|
|
<span class="ruby-keyword">end</span>
|
|
<span class="ruby-keyword">else</span>
|
|
<span class="ruby-identifier">authenticate_or_request_with_http_basic</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">username</span>, <span class="ruby-identifier">password</span><span class="ruby-operator">|</span>
|
|
<span class="ruby-identifier">user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by</span>(<span class="ruby-identifier">name</span><span class="ruby-operator">:</span> <span class="ruby-identifier">username</span>)
|
|
<span class="ruby-identifier">user</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">authenticate</span>(<span class="ruby-identifier">password</span>)
|
|
<span class="ruby-keyword">end</span>
|
|
<span class="ruby-keyword">end</span>
|
|
<span class="ruby-keyword">end</span></pre>
|
|
</div><!-- authorize-source -->
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div><!-- authorize-method -->
|
|
|
|
|
|
<div id="method-i-default_url_options" class="method-detail ">
|
|
|
|
<div class="method-heading">
|
|
<span class="method-name">default_url_options</span><span
|
|
class="method-args">()</span>
|
|
<span class="method-click-advice">click to toggle source</span>
|
|
</div>
|
|
|
|
|
|
<div class="method-description">
|
|
|
|
|
|
|
|
|
|
|
|
<div class="method-source-code" id="default_url_options-source">
|
|
<pre><span class="ruby-comment"># File app/controllers/application_controller.rb, line 46</span>
|
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">default_url_options</span>
|
|
{ <span class="ruby-identifier">locale</span><span class="ruby-operator">:</span> <span class="ruby-constant">I18n</span>.<span class="ruby-identifier">locale</span> }
|
|
<span class="ruby-keyword">end</span></pre>
|
|
</div><!-- default_url_options-source -->
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div><!-- default_url_options-method -->
|
|
|
|
|
|
<div id="method-i-set_i18n_locale_from_params" class="method-detail ">
|
|
|
|
<div class="method-heading">
|
|
<span class="method-name">set_i18n_locale_from_params</span><span
|
|
class="method-args">()</span>
|
|
<span class="method-click-advice">click to toggle source</span>
|
|
</div>
|
|
|
|
|
|
<div class="method-description">
|
|
|
|
|
|
|
|
|
|
<div class="method-source-code" id="set_i18n_locale_from_params-source">
|
|
<pre><span class="ruby-comment"># File app/controllers/application_controller.rb, line 34</span>
|
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">set_i18n_locale_from_params</span>
|
|
<span class="ruby-keyword">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-value">:locale</span>]
|
|
<span class="ruby-keyword">if</span> <span class="ruby-constant">I18n</span>.<span class="ruby-identifier">available_locales</span>.<span class="ruby-identifier">map</span>(&<span class="ruby-value">:to_s</span>).<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:locale</span>])
|
|
<span class="ruby-constant">I18n</span>.<span class="ruby-identifier">locale</span> = <span class="ruby-identifier">params</span>[<span class="ruby-value">:locale</span>]
|
|
<span class="ruby-keyword">else</span>
|
|
<span class="ruby-identifier">flash</span>.<span class="ruby-identifier">now</span>[<span class="ruby-value">:notice</span>] =
|
|
<span class="ruby-node">"#{params[:locale]} translation not available"</span>
|
|
<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-identifier">flash</span>.<span class="ruby-identifier">now</span>[<span class="ruby-value">:notice</span>]
|
|
<span class="ruby-keyword">end</span>
|
|
<span class="ruby-keyword">end</span>
|
|
<span class="ruby-keyword">end</span></pre>
|
|
</div><!-- set_i18n_locale_from_params-source -->
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div><!-- set_i18n_locale_from_params-method -->
|
|
|
|
|
|
</section><!-- protected-instance-method-details -->
|
|
|
|
</section><!-- 5Buntitled-5D -->
|
|
|
|
</div><!-- documentation -->
|
|
|
|
|
|
<footer id="validator-badges">
|
|
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
|
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.2.
|
|
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
|
</footer>
|
|
|