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:
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?
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.
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):
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):
It works fine. I have problem on the ActiveAdmin gem
form(formtastic-based
for form construction.
In the ActiveAdmin/Order I have
form do |f|
f.inputs do
f.input :title
f.has_many :line_items, :allow_destroy => true do |lp|
lp.input :language_pair
end
end
f.actions
end
I would like to pass two variable :source and :target just as the normal
form, but it seems I cannot do it with ActiveAdmin. I think I will go
with
a custom form.
I finally got it working in ActiveAdmin without a custom form. I’ll post
how I did it for references if somebody need.
First I set my custom attributes in the LineItem model:
class LineItem < ActiveRecord::Base
attr_accessor :source
attr_accessor :target
(it doesn’t work adding :source and :target to the ActiveAdmin file
under
permit_params, I get an error that there are no column with
:source/:target
if not added to the model with attr_accessor)
form do |f|
f.inputs do
f.input :title
f.has_many :line_items, :allow_destroy => true do |cf|
cf.input :source, :collection => Language.pluck(:lang)
cf.input :target, :collection => Language.pluck(:lang)
end
end
f.actions
end
controller do
def create @order = Order.create(:title => params[:order][:title])
params[:order][:line_items_attributes].each do |x, y|
source = Language.find_by_lang(y[:source])
target = Language.find_by_lang(y[:target])
pair = LanguagePair.find_by(:source_id => source.id, :target_id
=>
target.id) @order.line_items.create(:language_pair => pair)
end
create!
end
end
end