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 Downloads

CoffeeScript

Your Pragmatic Catalog

Cs f56ef62bc41b040664e801a38f068082a75d506d9048307e8096737463503d0b

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 836fee16e3757bcd4e2c21d064eee4fa81d7f93e4e9a44b1ffcd6c1d41c92a88

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 d3d2240713cce773840785de837acf822d235d1b77040a3e1ed9d8c014cff086

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

Your Downloads

CoffeeScript

Su Catálogo de Pragmatic

Cs f56ef62bc41b040664e801a38f068082a75d506d9048307e8096737463503d0b

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 836fee16e3757bcd4e2c21d064eee4fa81d7f93e4e9a44b1ffcd6c1d41c92a88

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 d3d2240713cce773840785de837acf822d235d1b77040a3e1ed9d8c014cff086

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
Run options: --seed 28159
 
# Running:
 
.......................FFF................................
 
Finished in 1.385990s, 41.8474 runs/s, 121.9345 assertions/s.
 
  1) Failure:
OrderNotifierTest#test_received [/home/rubys/git/awdwr/edition4/work-42/depot/test/mailers/order_notifier_test.rb:9]:
Expected: ["depot@example.com"]
  Actual: ["from@example.com"]
 
 
  2) Failure:
OrderNotifierTest#test_shipped [/home/rubys/git/awdwr/edition4/work-42/depot/test/mailers/order_notifier_test.rb:19]:
Expected: ["depot@example.com"]
  Actual: ["from@example.com"]
 
 
  3) Failure:
UserStoriesTest#test_buying_a_product [/home/rubys/git/awdwr/edition4/work-42/depot/test/integration/user_stories_test.rb:69]:
Expected: "Sam Ruby <depot@example.com>"
  Actual: "from@example.com"
 
58 runs, 169 assertions, 3 failures, 0 errors, 0 skips

16 Deployment 15.3 Task J3: Translating Checkout