GithubHelp home page GithubHelp logo

Comments (7)

timfjord avatar timfjord commented on June 24, 2024

In general, that fact that the i18n_backend_active_record_translation_path is not defined but the translations_path is has nothing to do with the initializer.
translations_path works only because you have an entry in routes.rb that defines a route named translations, so if you add something like

get '/something' => 'my_controller#my_action', as: :i18n_backend_active_record_translation

most likely it will work without url: translations_path

You can also try

class Translation < I18n::Backend::ActiveRecord::Translation
end

Adding the note about the path helper might be confusing because this gem doesn't really add routes and controllers and acts purely as a backend for I18n gem.

from i18n-active_record.

D4v1dW3bb avatar D4v1dW3bb commented on June 24, 2024

from i18n-active_record.

timfjord avatar timfjord commented on June 24, 2024

It is not recomennded to keep class Translation < I18n::Backend::ActiveRecord::Translation in the initializer, it should be in app/models/translation.rb
Basically this way we define our own AR model but inherit from the model from the gem.
I shared that just to illustrate that the issue wasn't really related to the initializer.

It is expected that I18n::Backend::ActiveRecord::Translation returns i18n_backend_active_record_translation_path.
Usage of the model in helpers like form_for or link_to is not supported because this gem doesn't provide any controllers, routes to handle that.

from i18n-active_record.

D4v1dW3bb avatar D4v1dW3bb commented on June 24, 2024

It is expected that I18n::Backend::ActiveRecord::Translation returns i18n_backend_active_record_translation_path.
Usage of the model in helpers like form_for or link_to is not supported because this gem doesn't provide any controllers, routes to handle that.

The gem does not provide it but it's expected the users of the gem are going to use it. Their not going to fill the translation table by hand. so they will need to make controllers, views and routes. Therefor the translation table should act like every other model whether it's installed by a gem or the programmer implements it himself.

from i18n-active_record.

timfjord avatar timfjord commented on June 24, 2024

You can use i18n_backend_active_record_translation name in your routes because this is what the model generates.

But I am going to revisit Translation = I18n::Backend::ActiveRecord::Translation part in the initializer and probably include class Translation < I18n::Backend::ActiveRecord::Translation model instead.

from i18n-active_record.

floydj avatar floydj commented on June 24, 2024

You can use i18n_backend_active_record_translation name in your routes because this is what the model generates.

So how exactly is this done?

from i18n-active_record.

timfjord avatar timfjord commented on June 24, 2024

You can use i18n_backend_active_record_translation name in your routes because this is what the model generates.

So how exactly is this done?

The easiest way is to have something like this in the routes.rb:

post '/some_path', to: 'my_controller#my_action', as: 'i18n_backend_active_record_translation'

But the custom model should be more convinient

from i18n-active_record.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.