Class: Idioma::PhrasesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Idioma::PhrasesController
- Defined in:
- app/controllers/idioma/phrases_controller.rb
Instance Method Summary collapse
-
#index ⇒ Object
GET /phrases.
-
#show ⇒ Object
GET /phrases/1.
-
#update ⇒ Object
PATCH/PUT /phrases/1.
Instance Method Details
#index ⇒ Object
GET /phrases
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/idioma/phrases_controller.rb', line 8 def index params[:locale_eq] ||= I18n.default_locale scope = Phrase.where(locale: params[:locale_eq]) if params[:q].present? scope = scope.where("i18n_key ilike ? OR i18n_value ilike ?", "%#{params[:q]}%", "%#{params[:q]}%") end respond_to do |format| format.html { @phrases = scope.paginate(:page => params[:page]) } format.csv { render text: PhraseExporter.to_csv(scope) } format.yaml { render text: PhraseExporter.to_yaml(scope) } format.json { @phrases = scope.paginate(:page => params[:page]) render json: { meta: { pagination: { current_page: @phrases.current_page, per_page: @phrases.per_page, total_entries: @phrases.total_entries } }, phrases: @phrases } } end end |
#show ⇒ Object
GET /phrases/1
44 45 46 47 48 49 50 |
# File 'app/controllers/idioma/phrases_controller.rb', line 44 def show respond_to do |format| format.json { render json: @phrase } end end |
#update ⇒ Object
PATCH/PUT /phrases/1
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/idioma/phrases_controller.rb', line 53 def update result = @phrase.update_and_update_backend(phrase_params) respond_to do |format| format.html { if result redirect_to [:edit, @phrase] else render :edit end } format.json { if result render json: @phrase else render json: { errors: @phrase.errors. }.merge(@phrase.attributes), status: :bad_request end } end end |