Thank you very much.
Using 'Language.all.permutation(2).to_a' I've got all the combinations
(A->B and B->A) and seeded the LanguagePair model. For the cost I was
thinking to puts a decimal column in the LanguagePair model.
At the moment I am working on the form(inside the lineitem views):
<div class="field">
<%= label_tag :from, "Source Language" %><br />
<%= select_tag :from, options_for_select(@from_lang), {id:
'source_select'} %>
</div>
<div class="field">
<%= label_tag :to, "Target Language" %><br />
<%= select_tag :to, options_for_select(@to_lang), {id: 'target_select'}
%>
</div>
and LineItem controller:
def new
@line_item = LineItem.new
@from_lang = Product.uniq.pluck(:from)
@to_lang = Product.where(from: @from_lang.first).pluck(:to)
end
I haven't got a lots of experience with the Rails and I am always searching
for a better ways to write things.
Regards
On Sunday, 28 September 2014 14:33:22 UTC+9, Vivek Sampara wrote:
>
> Paolo,
>
> I think you've going in the right direction but i'd recommend a few
> changes based on my experience. Translation Agency has different rates for
> each language. and the rate per language for A -> B Is not the same as B ->
> A. So its better to maintain the cost details in Another model unique for
> one direction.
>
> Language:
> has_many :language_translations
>
>
> LanguageTranslation
> belongs_to :language
> belongs_to :target_language, :class_name => "Language"
>
> #An float/integer field for cost.
>
> Also i dont think you have to specify foreign_key condition unless your
> association name and foreignkeys are different..
>
> eg blongs_to :car, :class_name => "Vehicle", :foreign_key => "bus_id"
>
> If you have car_id as the foreign key. then you can ignore mentioning it
> in the model.
>
> Cheers
>
>
>
>
> On Sun, Sep 28, 2014 at 6:40 AM, Paolo Wang <[email protected]
> <javascript:>> wrote:
>
>> Hi to all.
>>
>> I am working for a translation agency and I have the task to create an
>> auto-estimate system and ordering/invoicing administration system. I am
>> stuck on how to manage the language pairs.
>> I created a Language model with the language name and a LanguagePair with
>> a source language, a target language and a rate per words attributes. I
>> tried with:
>>
>> LanguagePair
>> belongs_to :source, :class_name => "Language", :foreign_key => "source_id"
>> belongs_to :target, :class_name => "Language", :foreign_key => "target_id"
>>
>> and also by replacing the source and target in the LanguagePair with a
>> string type and loading it with a Language.all.permutation(2).to_a and
>> eliminate the need for nesting.
>> In the end I will create a sort of cart and lineitem model and add the
>> LanguagePair to the cart as a LineItem.
>>
>> Is there a "best" way to do this maybe with a Language self-referential
>> model?
>>
>>
>> thanks in advance
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/rubyonrails-talk/c214ccfe-bc9a-4e5a-85fe-003a325fa2f0%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/rubyonrails-talk/c214ccfe-bc9a-4e5a-85fe-003a325fa2f0%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/a35094bb-261f-49fe-876c-4154fed20c67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.