yandex_inflect icon indicating copy to clipboard operation
yandex_inflect copied to clipboard

Feature request: Rails example in README or wiki

Open denispeplin opened this issue 12 years ago • 0 comments

I can prepare Rails example for README or Wiki, something like this:

app/models/inflection.rb

class Inflection
  def self.inflections(word)
    YandexInflect.inflections(word)
  end

  def self.genitive(word)
    { genitive: self.inflections(word)[1]['__content__'] }
  end
end

app/controllers/inflections_controller.rb

class InflectionsController < ApplicationController
  def show
    @inflections = Inflection.genitive(params[:id])

    respond_to do |format|
      format.json { render json: @inflections }
    end
  end
end

config/routes.rb

resources :inflections, only: [ :show ]

app/views/contracts/_form.html.erb

<%= simple_form_for(@contract) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :who_person %>
    <%= f.input :in_person %>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
    <%= link_to t(:back), :back, :class => 'btn' %>
  </div>
<% end %>

app/assets/javascripts/contracts.js.coffee

$ ->
  $('#contract_who_person').change ->
    $.getJSON("/inflections/" + $(this).val() + ".json",
      (data) ->
        $('#contract_in_person').val(data.genitive)
    )

denispeplin avatar May 31 '12 09:05 denispeplin