RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

p.s. I'm trying this on a windows machine.

It looks to be a known issue: https://github.com/sstephenson/eco/issues/29
I'm looking into alternatives to eco on windows

Avatar

Thanks for that I was missing the require => 'bcrypt', this solved the problem for me too.

Avatar

I'm having the same issue.
Did you manage to fix it?

Avatar

Hi,
I am New to rails.I have tried this one good examples through out the site.
But, Some Images are not cropping and default size is cropping an Image saving with defaults.
Plz Help?
Thanks for this Screen casts

Avatar

Got it. I had to customize nginx.conf

ruby
upstream unicorn_app1 {
  server unix:/tmp/unicorn.app1.sock fail_timeout=0;
}

server {
  listen 80;
  server_name app1.com;
  root /home/deployer/apps/app1/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn_app1;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

I used this with my "main" app

ruby
  listen 80 default deferred;

Do you see any ways to improve this?

Avatar

As I understand it, just the paid service is shutting down...but you can still use the product the paid service is based on copycopter-server but you have to host it yourself now, that's all.

This screen cast shows you how to do that.

So no worries if you still want to use it.

Avatar

About once a month you more than make up for the $9. Very impressed good sir, very impressed. Thank you for everything!

Avatar

How would I configure multiple websites on the same box? I know they would each be in a different directory by application name but how would I redirect using domain name. I know I would have to use apache virtual hosts but with Nginx I'm not sure.

Would it be better to have one IP address or multiple (looks like $1/IP on Linode).

Avatar

You could check if the model exists for the current locale (I think there is a method for that - would have to look it up) and if not redirect to the existing locale. Or add a text in that case saying something like "This Article doesn't exist in your language". And then you could link to all available language versions of that article. Clicking on one of the links, will change the app to the selected locale. That is also better in terms of usability compared to fallbacks, as it's not nice to have for example a russian article appear within a layout with english texts.

Avatar

Why are you not now using sprites for the area of your site shown in the video? Had to ask (practice what you preach, and all that).

Avatar

What about different size of images?

Avatar

It should probably be noted that at the moment there is a small glitch (regarding accessors / mass assignment) that prevents Globalize3 from working fully and seamlessly with rails 3.2.3. It will be fixed very soon, though!

Avatar

Hi Ryan, would you have some nice solutions to tackle the #82 issue of ancestry? (Problem with the to_json of the arrange method)

Avatar

Nice advice to put it in a initializer.
I also came across this solution a time ago. This works for some cases.
When you have a large website 10 or more locales its not handy to define a fallback for each locale. The point is you have to define the fallbacks static.

I am using an Article to explain my problem but a more suitable case is when you have an Festival. An Festival is held in a Country and has a language that is the base language for the Festival. The Festival is held in England so the organisation enters the data in the English language. The organisation decides also to translate the translate the website in the WK language. Now a German guys enters the website, what i dont want is that the website shows the Festival in the next best fallback language but the language its originally created with. Because a Festival can also be entered in the WK language(original) and English language (translation) then a German user needs to see the Festival information in WK.

Then static fallbacks wont help me..

Avatar

Installing growl-notify from http://growl.info/downloads fixed the problem for me. Hope this helps.

Avatar

Since you are already overwriting stuff you could try this in an initializer

ruby
    module Globalize

    class << self

        def fallbacks(locale = self.locale)
          case locale
          when :en then [:de, :wk]
          when :wk then [:de, :en]
          when :de then [:wk, :en]
          end
        end

      end
    end

Non tested and found at stackoverflow but seems like it could work. Checkout the thread to see more details
http://stackoverflow.com/questions/7942450/is-it-possible-to-make-rails-i18n-locales-fallback-to-each-other

Avatar

Hello guys and Ryan,

I was having a great challenge with Globalize3 regarding translating models on a website. Globalize3 relies on models created by a base locale set by I18n.locale or config.i18n.default_locale. Now lets have this situation when video above has three locales, WK, DE and EN (EN set as default). I have my fallback set to the en locale.

When I enter articles in english all goes fine, all the entries are now English for all locales. But for example when i try to make an article in WK language only, Globalize wont fall back to that language when the user browses the English or German language. For example when I view the page in German it still falls back to the English locale which is not set. Any suggestions how to fall back to the locale in which the Model is originally created when other locales are not set?

So my goal was; when a Article is created in a locale (WK) other then the default_locale (EN), the application needs to show that locale (WK) in the article as fallback locale. Even when i enter a translation for the default locale (EN) and the user requests the page in German (DE) the article is shown in the (WK) locale.

What i did is create an base_locale attribute to the Article model and tried overriding the read_attributes globalize uses. Here is some code

ruby
class Language < ActiveRecord::Base
attr_accessible :locale, :name
end


class Article < ActiveRecord::Base 

translates :title, :description, :fallbacks_for_empty_translations => true
attr_accessible :title, :description :base_locale_sym
belongs_to :base_locale, :class_name => "Language", :foreign_key => "base_locale_id"
before_save :set_base_locale_cache
def set_base_locale_cache
    if self.base_locale_id_changed?
      unless self.base_locale.blank?
        #sets the base locale cache for the created Article
        #i dont want to query Article.base_locale each time...
        self.base_locale_sym = Language.find(self.base_locale_id).locale
      else
        self.base_locale_sym = ""
      end
    end
  end

def read_attribute(name, options = {})
    #when the translated_locales does not include the i18n.locale try to show the model in the locale in which the Article was first created.
    unless self.translated_locales.include? I18n.locale.to_sym
      #merge the options hash
      options.merge(:locale => self.base_locale_sym)
    end
    super(name,options)
  end

end

This idea worked quite fine, but i had really issues with updating and generating models. Maybe someone got a better idea?

I couldn't figure out this puzzle so i stopped it 3 months ago. Since this railscast is about globalize, I thought maybe we can solve it..

Avatar

Is it also possible to use realiable validations?

Thanks so much for this episode :), great stuff

Avatar

Good stuff - I have the same question as this guy, regarding how to integrate ElasticSearch into a model that uses Globalize3.

Avatar

We fork this gem and rewrite to more flexible globalize3

No more need to write create_translation_table! in migrations.

Just write in AR model translates "title:string", "content:text" and call rake db:globalize:up.

It automatically synchronize translated columns with database (create/drop table or add/change/remove column).

Avatar

If you don't have a lot of languages but just two or three or so, you could keep things simpler with multiple columns in the same table. We wrote Traco for that recently, inspired by an earlier plugin called translatable_columns.

Avatar

Hi Guys,

i don't really understood, how can deploy:setup successfully completed?
Because we can't create symlinks to non existing files.
Only after deploy:cold we get current folder with nginx.conf and unicorn_init.sh files.

ruby
 ** [out :: 172.17.11.10] creating symbolic link `/etc/nginx/sites-enabled/abc' to `/home/rails/apps/abc/current/config/nginx.conf'
 ** [out :: 172.17.11.10] : No such file or directory

Or I don't understand something.

Avatar

At 9:49, my response.responseText contained {"name":["can't be blank"]}
and not {"errors": {"name":["can't be blank"]}} (i.e. there was no "errors" key).

So when parsing the messages within entries/index.js.coffee#handleError method, I did

coffee
errors=$.parseJSON(response.responseText)

instead of

coffee
errors=$.parseJSON(response.responseText).errors

I have rails 3.1.2, and my web browser is Chrome 16.0.912.77.

Avatar

Has anyone else run into a mass assignment error when trying to create a new piano?

ActiveModel::MassAssignmentSecurity::Error in Refinery::Pianos::Admin::PianosController#create

Can't mass-assign protected attributes: name, dimensions, manufactured_on(1i), manufactured_on(2i), manufactured_on(3i), upright, photo_id, description, position

Here's screenshot of error:
http://grab.by/cWGE

If anyone has an idea how to solve this, would be appreciated.

Avatar

Has anyone tried tr8n?

http://github.com/berk/tr8n

http://wiki.tr8n.org/slides

No need for YML files, full support for language context rules and language cases. Uses crowd-sourced or professional translator provided translations.

Here is what some of the translations would look like. t method is replaced with tr.

<%= tr("Hello World!") %>

<%= tr("Name:", "User name label") %>

  • uses description to provide context for the label

<%= tr("You have {count|| message} in your mailbox.", nil, {count: 5}) %>

  • will use numeric rules and inflectors to provide the right form for message/messages

<%= tr("{actor} sent {target::dat} a message.", nil, {actor:user1, target:user2}) %>

  • will use gender of {actor} user to provide the right form for word "sent" and apply Dative language case to the name of target user token.

<%= tr("{actor} sent {target::dat} [strong: {count|| message}].", nil, {actor:user1, target:user2, count:5}) %>

  • similar to the above example, but also adds a decoration token around the number of messages. Here is an example in English:

Michael sent Anna 5 messages.

In Russian this would need 9 translations based on the gender of actor (male, female, unknown) as well as value of count: 3 cases as well. It can translate names as well, if you so desire.

Михаил послал Анне 5 сообщений.

The technology is very powerful and has been used by Geni and Yammer and a few other companies and is now open sourced.

(Disclaimer: I am a tr8n developer)

Avatar

If you try out the master branch of spree right now, you could see a vast spped boost in development because Spree now requires Rails 3.2 app.

Avatar

Is there documentation on the engine generator? I was trying to lookup how I could specify a field type for uploading files instead of photos.

nm... I should look around better
http://refinerycms.com/guides/multiple-resources-in-an-extension

Avatar

Ryan thanks for the excellent deployment series.

I'm attempting to deploy to Linode following these recipes and get the following error when I try to cold deploy:

ruby
failed: "sh -c 'if [ -d /home/deployer/apps/alexapp/shared/cached-copy ]; then cd 
/home/deployer/apps/alexapp/shared/cached-copy && git fetch -q origin && git 
fetch --tags -q origin && git reset -q --hard 
bdfebfaa7b77893a800afb9ccf85d66296ed15e0 && git clean -q -d -x -f; else git 
clone -q git@github.com:alexagui/alexapp.git 
/home/deployer/apps/alexapp/shared/cached-copy && cd 
/home/deployer/apps/alexapp/shared/cached-copy && git checkout -q -b deploy 
bdfebfaa7b77893a800afb9ccf85d66296ed15e0; fi'" on 50.116.34.XXX

Suggestions in right direction will be greatly appreciated.

Avatar

Hello,
I implement Fixtures as you. But when I run rake db:seed, I meet error:
rake aborted!
uninitialized constant Fixtures

My seed.rb is:
require 'active_record/fixtures'
Fixtures.create_fixtures("#{Rails.root}/db", "categories")

My categories.yml is in db directory:
one:
name: Flying

I search on google and don't find anything. Please help me, thank you!

Avatar

I have the same issue. Did you get this resolved? I can't find an indent error any where in my code.

Avatar

A nice introduction done at a good pace. Content was pretty informative. Thanks Ryan!

Avatar

Hey Ryan,

if you have time, it would be great if you could revise this episode!

Avatar

Hey Alan,
You were correct. Originally I followed your instructions and added a "require tree ." in the last line. But for whatever reason, I left the original "require tree ." in the line above. So the problem was still there (and Stuart spotted that in his comment below).

Thanks a lot!

Sunil

Avatar

Hey Stuart,
You are correct. Not sure how I missed that other "require tree ." above. Thanks a lot.

Sunil

Avatar

Hi Ryan, great work on this gem!

However, how do you test it? Capybara-webkit does not seem to like it:

http://localhost:9292/faye.js|1|NETWORK_ERR: XMLHttpRequest Exception 101: A network error occured in synchronous requests.
Avatar

I see you have require_tree . twice in the file.

You only need it once, at the bottom of the file.
Root level files get required first, if you use require_tree.
So raffler.js.coffee is getting processed before all the other files, such as the routers etc.

Avatar

+1

Except the server validations, I think that's pretty useful information ;)

Avatar

Sorry, but calling that setup 'Very unsecure' is a big exaggeration. It is not optimal, but definitely not insecure.

Avatar

The edge version of https://github.com/seyhunak/twitter-bootstrap-rails now as support for simple_form and I18n right out of the box.

Avatar

The edge version of https://github.com/seyhunak/twitter-bootstrap-rails now as support for simple_form and I18n right out of the box.

Avatar

Why not making this an option to the official repo ?

Avatar

Thanks for this, it's so obvious! But yet I completely overlooked it! :)

Avatar

Hi, it seems interesting, I'm curious about the price for the "Beginner" plan once the beta stage will end.

It would be really useful an interface for the globalize3 gem, have you planned it?

Avatar

in rails 3.2.3 you need to run your dummy server with the

rails s

command from inside the tests/dummy folder, not at the root of the engine

docs:

http://edgeguides.rubyonrails.org/engines.html