I have a Phrase class that has_many Phrase as Translation .
application / models / phrase.rb
class Phrase < ActiveRecord::Base has_many :translatabilities has_many :translations, through: :translatabilities has_many :inverse_translatabilities, class_name: "Translatability", foreign_key: "translation_id" has_many :inverse_translations, through: :inverse_translatabilities, source: :phrase accepts_nested_attributes_for :translatabilities end
application / models / phrases_controller.rb
class PhrasesController < ApplicationController def index @phrases = Phrase.all.page params[:page] @translations = @phrases.count.times.map do |i| translation = Phrase.new translation.translatabilities.build translation end end end
And I want to add forms of "translatability" for each "phrase".
application / views / phrases / index.html.erb
<table> <tbody> <% @phrases.each do |phrase| %> <tr> <td><%= phrase.text %></td> </tr> <tr> <td> <%= form_for @translations do |f| %> <%= f.text_field :text %> <%= f.submit 'translate' %> <%= f.fields_for :translatabilities do |t_form| %> <%= t_form.hidden_field :id %> <% end %> <% end %> </td> </tr> <% end %> </tbody> </table>
This code has an infinite loop error.
undefined method `phrase_phrase_phrase_phrase_phrase_phrase_...
How to create forms for translating source phrases?
application / models / translatability.rb
class Translatability < ActiveRecord::Base belongs_to :phrase belongs_to :translation, :class_name => 'Phrase' end
source share