Agile Web Development with Rails, Edition 4

16 Deployment 15.3 Task J3: Translating Checkout

15.4 Task J4: Add a locale switcher.

58 (tests|runs), 174 assertions, 0 failures, 0 errors.
<0> expected to be
>=
<1>.

Traceback:
  /home/rubys/git/awdwr/edition4/checkdepot.rb:36:in `assert_test_summary'
  /home/rubys/git/awdwr/edition4/checkdepot.rb:417:in `block in <class:DepotTest>'

Add form for setting and showing the site based on the locale.

Use CSS to position the form.

edit app/assets/stylesheets/application.css.scss
.locale {
  float: right;
  margin: -0.25em 0.1em;
}

When provided, save the locale in the session.

edit app/controllers/store_controller.rb
  def index
    if params[:set_locale]
      redirect_to store_url(locale: params[:set_locale])
    else
      @products = Product.order(:title)
    end
  end
edit app/views/layouts/application.html.erb
  <div id="banner">
    <%= form_tag store_path, class: 'locale' do %>
      <%= select_tag 'set_locale', 
        options_for_select(LANGUAGES, I18n.locale.to_s),
        onchange: 'this.form.submit()' %>
      <%= submit_tag 'submit' %>
      <%= javascript_tag "$('.locale input').hide()" %>
    <% end %>
    <%= image_tag("logo.png") %>
    <%= @page_title || t('.title') %>
  </div>

Try out the form

get /en

Your Cart

CoffeeScript $36.00
Total $36.00

Your Pragmatic Catalog

Cs

CoffeeScript

CoffeeScript is JavaScript done right. It provides all of JavaScript's functionality wrapped in a cleaner, more succinct syntax. In the first book on this exciting new language, CoffeeScript guru Trevor Burnham shows you how to hold onto all the power and flexibility of JavaScript while writing clearer, cleaner, and safer code.

$36.00
Ruby

Programming Ruby 1.9 & 2.0

Ruby is the fastest growing and most exciting dynamic language out there. If you need to get working programs delivered fast, you should add Ruby to your toolbox.

$49.95
Rtp

Rails Test Prescriptions

Rails Test Prescriptions is a comprehensive guide to testing Rails applications, covering Test-Driven Development from both a theoretical perspective (why to test) and from a practical perspective (how to test effectively). It covers the core Rails testing tools and procedures for Rails 2 and Rails 3, and introduces popular add-ons, including Cucumber, Shoulda, Machinist, Mocha, and Rcov.

$34.95
post /en
You are being redirected.
get http://localhost:3000/es

Carrito de la Compra

CoffeeScript 36,00 $US
Total 36,00 $US

Su Catálogo de Pragmatic

Cs

CoffeeScript

CoffeeScript is JavaScript done right. It provides all of JavaScript's functionality wrapped in a cleaner, more succinct syntax. In the first book on this exciting new language, CoffeeScript guru Trevor Burnham shows you how to hold onto all the power and flexibility of JavaScript while writing clearer, cleaner, and safer code.

36,00 $US
Ruby

Programming Ruby 1.9 & 2.0

Ruby is the fastest growing and most exciting dynamic language out there. If you need to get working programs delivered fast, you should add Ruby to your toolbox.

49,95 $US
Rtp

Rails Test Prescriptions

Rails Test Prescriptions is a comprehensive guide to testing Rails applications, covering Test-Driven Development from both a theoretical perspective (why to test) and from a practical perspective (how to test effectively). It covers the core Rails testing tools and procedures for Rails 2 and Rails 3, and introduces popular add-ons, including Cucumber, Shoulda, Machinist, Mocha, and Rcov.

34,95 $US
rake test
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from rescue in <class:Exception> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/web-console-2.1.2/lib/web_console/integration/cruby.rb:37)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from block in <top (required)> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/web-console-2.1.2/lib/web_console/extensions.rb:18)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from included at /home/rubys/.rvm/gems/ruby-head-n50123/gems/turbolinks-2.5.3/lib/turbolinks/xhr_url_for.rb:7)
rake aborted!
SyntaxError: /home/rubys/git/awdwr/edition4/work-220/depot/test/controllers/line_items_controller_test.rb:23: syntax error, unexpected keyword_end, expecting '}'
/home/rubys/git/awdwr/edition4/work-220/depot/test/controllers/line_items_controller_test.rb:68: syntax error, unexpected end-of-input, expecting keyword_end
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:274:in `require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:274:in `block in require'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:274:in `require'
/home/rubys/git/rails/railties/lib/rails/test_unit/runner.rb:118:in `block in run_tests'
/home/rubys/git/rails/railties/lib/rails/test_unit/runner.rb:117:in `each'
/home/rubys/git/rails/railties/lib/rails/test_unit/runner.rb:117:in `run_tests'
/home/rubys/git/rails/railties/lib/rails/test_unit/runner.rb:88:in `run'
/home/rubys/git/rails/railties/lib/rails/test_unit/runner.rb:82:in `run'
/home/rubys/git/rails/railties/lib/rails/test_unit/testing.rake:9:in `block in <top (required)>'
Tasks: TOP => test
(See full trace by running task with --trace)

16 Deployment 15.3 Task J3: Translating Checkout