RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

You might want to still use transactions for any other tests (that way they're faster).

Something like this would work:

  config.use_transactional_fixtures = false

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    if example.metadata[:js]
      DatabaseCleaner.strategy = :truncation
    else
      DatabaseCleaner.start
    end
  end

  config.after(:each) do
    DatabaseCleaner.clean
    if example.metadata[:js]
      DatabaseCleaner.strategy = :transaction
    end
  end

Avatar

Thanks for yet another great episode! The :escape options is not taken into account when using the i18n::Backend::Chain though, so '.' are always escaped.

It seems that's there's a pull request fixing it waiting:
https://github.com/svenfuchs/i18n/pull/85

Avatar

undefined local variable or method `sort_column' for #<#<Class:0x236d5e8>:0x236b920>

with Rails 2.3.11.

Any help is welcome.

Avatar

I do integration testing with Rspec but instead I use Steak and Akephalos, I have created a demo https://github.com/boriscy/akephalos_steak to setup a rails app to test, it's a simple configuration. I have also created this tutorial in spanish http://www.boliviaonrails.com/2011/03/01/testeando-javascript-con-steak-y-akephalos/

Avatar

Digging the blend of Rspec and Cucumber. This will come in handy.

Avatar

A caveat here is that webmock and other net/http mockers will give you a hard time by interfering with your capybara requests with this setup. Suggestions exist to configure Selenium to use Curb instead.

Avatar

There's also DSL, previously known as Steak, that helps to write request specs in more Cucumber-like way (focusing on user stories). It's built into Capybara master and works just fine.

Avatar

Perhaps you have rspec included only in your test group, rather than in both the test and development groups in your gemfile, like in the 'cast.

any gems which have generators or command line tools of their own have to exist in the development environment as well so you can access them. otherwise you will get 'not found' errors.

Avatar

@/users/719 make sure you have the rspec gem in the development group, not just in the test group in your Gemfile.

Avatar

thanks for the great tutorial but i just get Could not find generator rspec:install. error ?

Avatar

I used Google as an OpenID provider and needed the user's email address.

In the create_with_omniauth method use this:

auth["user_info"]["email"]

to get the email address of the user. You'll have to add a new field to the User model to save it tho.

Avatar

Ryan, how do you get that mysql style output from rails c? I really like that compared to the default output formatting

Avatar

Actually I changed my mind after watching this episode again, and made imporovements to the backend. Supports Redis and MongoDB, nicer UI. Thanks for showing me chainable backend in this episode.

As always, you're right on time -- I had to improve this engine for another client, and this episode helped a lot!

New project is here:
https://github.com/amberbit/translator

Avatar

Just in case anyone else was looking for solution Kaminari+Meta_Search, long story short, I added the :page under #Results, debug... into meta_search.rb

there is a reference at:
http://metautonomous.lighthouseapp.com/projects/53012/tickets/51-make-it-working-with-kaminari

change made per latest commit by author:
https://github.com/ernie/meta_search/commit/4fc9ab8f9c47b48e733ce867c5919f009a66d7c6

since then, working very well

Avatar

i'm having problems with this code,
i'm getting Errno::ECONNREFUSED in UsersController#create

more precisely Connection refused - connect(2) exactly in the delivery line

and i dont now how to fix it...
anyone now?

by the way your site is amazing...

Avatar

Awesome episode Ryan. I needed this in an existing Rails 2.3.8 project, so I made a few changes to suit.

If anyone is interested, my fork is at: https://github.com/MeetDom/railscasts-episodes/tree/rails238/episode-255

Includes the sqlite3 db with products and has fixes to deal with undoing a create which was throwing an ActiveRecord::RecordNotFound error. I substituted @template for view_context since it's not available in until Rails 3.

Hope this helps someone else still using Rails 2.3.8.

Avatar

hey,
is it possible to track files ? like images ? that would be nice :)

Avatar

Thank you Ryan.
As usual, you're my first reference on Rails world!

Go ahead so!

Avatar

If you're getting error 401 - OAuth::Unauthorized, make sure you edit the settings of your Twitter application as follows:

- Application Type: Browser
- Callback URL: http://127.0.0.1:3000/auth/twitter/callback

Avatar

Hi Ryan!

These 6 screencasts really helped to sort things out, thanks a lot for that. Are you still planning to cover recurring payments?

Avatar

Wow, that's cool. I did something very similar a few months ago for a client and made it open source. It's using Mongodb backend instead, and there is only one big form where user can enter details. Check it out here: https://github.com/hubertlepicki/GoTranslateYourself

I found it useful to provide default dummy fallback locale -- in dev.yml file -- so that even English-speaking clients can make ammendments to wording on the site such way.

Avatar

Found a solution (kinda). I guess ImageMagic has some problems working with Ruby 1.9

http://stackoverflow.com/questions/2838307/why-is-this-rmagick-call-generating-a-segmentation-fault

Avatar

My local server keeps crashing whenever I try and use a rmagick command in CarrierWave.

I've just installed ImageMagic. I'm pretty sure it should be working fine. The "convert logo: logo.gif" "display logo.gif" test command suggested by rmagick work in my terminal.

When I try and create a thumb version with "process :resize_to_limit," Rails crashes and I get a message saying "You may have encountered a bug in the Ruby interpreter or extension libraries"

Any thoughts on what might be causing the crash?

Avatar

Cannot wait to try this with a key-value store. Ruby wasn't happy when I put unicode string (??? - peace) in yaml file. Ended up using ActiveRecord with DB round trip overhead.

Avatar

Here's a little migration tip for tose still on attachment_fu :

http://ruby.simapse.com/2011/03/migrate-attachmentfu-to-carrierwave.html

Avatar

For those who are interested: there is a Redis backed i18n solution in my redis-store gem (beta4 version): https://github.com/jodosha/redis-store/blob/master/lib/i18n/backend/redis.rb

Avatar

Ryan, have you thought about processing video in rails. I think it would be a great screencast.

Avatar

Thank you for another great screencast!
Speaking of internationalization, I'd really enjoy a Railscast on the woes of document and string encodings with Ruby 1.9.2 and Rails (the good ole' multibyte US-ASCII error). It's a real headache for many Rails developers. But I do realize that it's not really a Rails issue.

Avatar

Great post and Great discussion.

Avatar

@Andy Stewart, correction granted. I have been looking at the problem, and it seems like -- at least for purposes of an undelete function -- it ought to be straightforward-ish, at least for certain types of associations.

Clearly, if the programmer is setting up a complicated transaction in which he is "manually" manipulating associations, she should be preparing to undo the transaction herself, either by embedding the information in the paper-trail records or so forth.

But because Rails permits associations to be manipulated using the :dependent => :foo options, a bunch of records can be deleted without the programmer under the metal. But in this case, it seems to me that it ought to be straightforward, using the Activerecord reflection capabilities to identify the tables that will contain autodeleted records, and then to set up a query on the versions of that table "pointing" back to the id of the principal deleted record to find the contemporaneous delete versions. and then to undelete those records, and so on.

I think reflection can automate this to some extent, at least for has_many and belongs_to types of associations with :dependent options. I don't need to look at harder questions for the undelete function, thankfully.

Or am I missing stuff?

Avatar

Thanks a lot for update about tolk from dhh! Will try soon, but doc is already very promising...

Avatar

Great screencast Ryan! Would be awesome to have one focusing solely on Redis and caching one day.

Avatar

Read up about monit vs god and i think i'll give god a try at http://dealsking.de - hate it when delayed_job crashes without notice ;)

Avatar

@Andrew Greenberg, a small correction: Paper Trail doesn't lose a deleted resource's assocations. They're all present and correct in its versions table.

The hassle (for now) is that you have to restore the assocations from that information yourself, rather than Paper Trail doing it for you. If you think of a good way to do this, please let me know.

Avatar

This is a beautiful thing. As more and more experts in user design are bringing web interfaces into the 21st century, its a gem that our tools are starting to catch up.

Aza Raskin (Jef's son) recently wrote on this subject, explaining its virtues in http://www.alistapart.com/articles/neveruseawarning/

and Ryan comes up with this pretty ditty just days after I started thinking about it. I got excited and started messing around it at once.

A few areas for refactoring:

1) REST. I'm not sanguine about a versions controller delivering a reversion command in modern-day rails. Though its not a meaningful difference, it feels more right to implement this as a reversion subresource of a a version resource, so that versions#reversion becomes reversion#new. Ok, I'm anal after drinking the kool-aid, but it was cherry kool-aid! So, I prefer

resources versions do
   resource reversion
end

even though the urls are completely the same.

2. MVC. I really don't like making links in controllers, particularly with all that logic there. To me, this stuff belongs in the view and/or model layers. And rails provides for communication with flash, so why not use it? I would suggest:

redirect_to url, :flash => {:notice => msg, :reversion => x.versions.etc.id}

and then build your interface in the view layer, where you can custom-tailer the presentation as you always should.

3) There is a bug. Things blow up if you are updating a product that does not already have at least one version (at least the create version). This can (and is likely) to happen when you are building an undo structure over an existing database. Many ways to address this.

I, too, lament the limitations of paper_trail in terms of losing associations for a deleted resource. I wonder if model layer CRUD is too low-level for a higher-level concept such as an undo, which is generally more transactional in nature?

Great stuff, Ryan. You tweaked my mind with an elegant and straightforward spike at a non-trivial problem. Next step, how to integrate this undo functionality more generally, ultimately for inclusion in the framework itself... Aza thinks we should, and when has he ever been wrong?

Avatar

Oh, and congratulations on your 2**8th episode!

Avatar

Funny how you'd do a Railscast on i18n just a couple of days after I took a lab day to explore webtools for handling the translation process.

We have about 3000 strings translated into five languages. Editing yaml-files in this situation will cause brain damage.

For now, we've settled on http://webtranslateit.com, but there are others like http://99translations.com. They provide a really nice translation GUI. Importing our locale files took a while, but the export was quick and gave me the opportunity to do a massive cleanup of our translation keys.

I feel that when an internationalized project grows big, there is a large payoff in using a professional translation tool. Spend your time on your app, instead of maintaining a custom tool for translations. If your translation files are big, you'll make the money you spend on the translation tool back in very little time.

Avatar

I like Translate (https://github.com/newsdesk/translate) which lets you edit the yml files from a web interface with some smart search options.

Avatar

Thanks again for this great post.

I'm living in Quebec (Canada). Every projects I'm working on must accomodate French an English users. The approch presented in this screencast is very simplice and neary unusable inside medium and large projects.

For us, translation is part of our workflow.

Generally, before beginning a project, we decide the language used by default (language inside the code). English is often appropriate. Then, during the modeling stage, we select names to be used for models and attributes in both french and english. (I'm working on a generator that will create the yml files under config/locales/models/... and the appropriate keys).

Combined with a generic series of translations, this is sufficient for 99% of administrative views. It is very easy to combine with meta_search, simple_form and other gems.

For the translation of database content, views and static views, we use several techniques. It depends on the client context.

Some content must exist simultaneously in both languages. Others do not have this restriction. Some pages are so different from one language to another... So we produce them separately. (about.en.html.erb, about.fr.html.erb...) we also add by composition some methods to the models.

If one day you have any interest, I would be happy to share my screen with Skype and walk you through one of my projects... In English of course!

Avatar

How about tolk https://github.com/dhh/tolk?
Nice 1<<8 episod :)

Avatar

This could be really great when using it with Tolk (https://github.com/dhh/tolk).

Thanks a lot!

Avatar

Nice solution! You can also make a webinterface to modify the yaml files with the translations. That way you don't need to switch to another backend.

Avatar

what does the --pre option do in gem install?

Avatar

Excellent!

Congratulations on episode 2**8 = 256

Avatar

After translating a simple rails app (starting with nifty-generators) I'm very happy to understand translation backends.
I very much like the Idea of a translation web-interface, but I'm not yet sure about redis. Maybe it makes sense in a large environment, but for my little personal use it's too much effort to run another server. Additionally I like the idea of having a file unter version control.

However it would be great to use a web-interface that is capable to trace all the "missing translation" entries when I run my app in development mode and to then display them in a matrix (item by supported language) to get an overview in what's missing.

Is there a gem like this out there?

Avatar

Was just looking at something like that! Thanks for yet another great railscast.

Avatar

Thanks Ryan, excellent screencast!

Avatar

It seems like there is a problem with nested form and uniquness conditions.

If I have many Frobs per Person object, with a condition on the Frobs being that the start_date of a Frob has to be unique for a person, then if, using a nested for, I delete a Frob, and add a Frob with the same date, then I get a uniqueness validation error.

Avatar

Using "html_safe" works for flash :notice messages and it is better than a blanket rendering of all :notice messages using raw()

So, that'll become:

redirect_to :back,
  :notice=>"Undid #{@version.event}. #{link}".html_safe

Avatar

@ed or anyone else with the dynamic datepicker problem: include another call to the regular function within the add_fields function.