T
T
tuturap2014-12-03 02:50:58
Ruby on Rails
tuturap, 2014-12-03 02:50:58

How to properly implement data sampling (filtering) in RoR?

Hello.
There is a page on which books are placed. The database contains books in different languages ​​(lang field), but only books in one language selected by the user are shown.
How to implement the user's choice in which language to show books? At the moment, I just have implemented links with the language.
As I understand it, it will be necessary to store a cookie with the selected language, since there will still be a search for books in the selected language, and the user can also leave and return to the page.
PS I just started to understand RoR and if I ask a stupid question, don't kick me hard.
method
@lang = Book.select(:lang).distinct
view

- @lang.each do |name|
    = link_to name.lang

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Krasnodemsky, 2014-12-03
@tuturap

Both cookies and LocalStorage are fine.
Provide a choice of language when the user first signs in.
The initial value can also be retrieved from the Accept-Language HTTP header.
If the user is authenticated, store the value in the database.

A
Alexander Wolf, 2014-12-03
@mannaro

Do you have authorization? If yes, then give the user the opportunity to specify the language in the profile. Then you don't have to carry a cookie.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question