Agile Web Development with Rails, Edition 4

Agile Web Development with Rails, Edition 4

16 Deployment 15.3 Task I3: Translating Checkout

15.4 Task I4: Add a locale switcher.

Expected at least 1 element matching "option[value='es']", found 0.

Traceback:
  /home/rubys/svn/rails4/Book/util/checkdepot.rb:264

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

Use CSS to position the form.

edit public/stylesheets/depot.css
.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_path(:locale => params[:set_locale])
    else
      @products = Product.all
      @cart = current_cart
    end
  end
edit app/views/layouts/application.html.erb
    <%= 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').each(Element.hide)" %>
    <% end %>

Try out the form

get /en

ActiveRecord::StatementInvalid in StoreController#index

SQLite3::CorruptException: database disk image is malformed: SELECT "products".* FROM "products" ORDER BY title

Rails.root: /home/rubys/svn/rails4/Book/util/work-188/depot

Application Trace | Framework Trace | Full Trace
app/controllers/store_controller.rb:14:in `index'

Request

Parameters:

{"locale"=>"en"}

Show session dump

Show env dump

Response

Headers:

None

rake test
/home/rubys/.rvm/gems/ruby-1.8.8-r30068/gems/rake-0.8.7/lib/rake/alt_system.rb:32: Use RbConfig instead of obsolete and deprecated Config.
(in /home/rubys/svn/rails4/Book/util/work-188/depot)
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.8-r30068/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
..............................................
Finished in 1.730668 seconds.
 
46 tests, 77 assertions, 0 failures, 0 errors
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.8-r30068/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
...
Finished in 1.158635 seconds.
 
3 tests, 75 assertions, 0 failures, 0 errors
Errors running test:units!

16 Deployment 15.3 Task I3: Translating Checkout