Zyth23
Zyth23

Reputation: 23

I18n.locale troubles when sorting datas from a table

I have a little problem with my application rails and locale params.

I successfully enabled all my controllers' routes in the routes.rb file with my :locale value between domain and controller in the URL.

When the controller need to show a sorting of many datas from one Table with the method "Data.find(:all)" or "Data.all" or custom condition to see all, I get a routing error.

If there is only une data filtered by an ID or ONE parameter to render only ONE data, all works fine.

In the logs I only see "500 internal error" and the error as I see on my site (development mod).

Here is the full error code:

No route matches {:action=>"edit", :controller=>"translation_english_words", :locale=>#<TranslationEnglishWord id: 1, data: "song", transvalue: "choubidoubop">}

The URL is: "http://domain/fr/translation_english_words" (:domain/:locale/:controller)

My controller is "translation_english_words" and has a table with same name in my database.

The table has 3 column, id:autoincrement, data:string, transvalue:string

I saw the part ":locale" in the route doesn't contain the "fr" or "en" or other locale is must contain. and it just not contain data begining with " and finishing with " as all other params like ":action" and ":controller"

Actually I need locale just for detect the wished language.

Not using any "t(:value)" for translation atm.

This error is not only on this controller, but on EACH controllers that require sorting more than one UNIQUE scoped data from any table.

Someone have any idea about how to solve my problem?

Upvotes: 0

Views: 163

Answers (2)

Zyth23
Zyth23

Reputation: 23

Ok everyone, I found "why" the route failed.

It seem this caused the route to break:

Controller:

<pre>
    def index
    @translation_english_word = TranslationEnglishWord.all
    end
</pre>

View:

<pre>
    &lt;% for translation_english_word in @translation_english_word %&gt;
    &lt;%= link_to "Edit", 
    edit_translation_english_word_path(translation_english_word) %&gt;&lt;br /&gt;
    &lt;% end %&gt;
    &lt;%= link_to "New English Translation", new_translation_english_word_path %&gt;
</pre>

The paths that call edit_translation_english_word_path and new_translation_english_word_path seem to break the route. I don't know Why, but removing them, resolved my issue, but it still isn't clear why this happens, and I'd like to understand why if anyone can comment to me?

Upvotes: 0

ecoologic
ecoologic

Reputation: 10420

would be great to know the actual implementation of your routes, have you followed the guides? seems you should have something like this:

# config/routes.rb
scope "/:locale" do
  resources :translation_english_words
  # [...] # all other controllers
end

I'm not sure you

successfully enabled all my controllers' routes in the routes.rb

In fact your controller is interpreted as locale, which makes me think that the routing attempt is different.

Also I can't really understand your url: http://domain/fr/translation_english_words Shouldn't this be something like": http://domain.lvh.me:3000/fr/translation_english_words if you're working in a local development environment?

Upvotes: 1

Related Questions