views:

32

answers:

1

Hi,

I have the model:

  • User -1---n- Transaction(amount,description, date)
  • User -1---n- TransactionImport -1---n- TransactonImportField(name,value)

(personal expense tracking app).

What I want to achieve is this:

  1. User opens URL and pastes the CSV with the list of transactions.
  2. User submits it.
  3. System extracts data from CSV into TransactionImport (row) + TransactionImportField (cell).
  4. User can choose which column means what (amount, description, date) from the imported data in TransactionImport(Field).
  5. User click save and the system transfers TransactionImport into the Transaction.

What I can't seem to get right is the fact that step 3 creates multiple records of TransactionImport (and related TransactionImportField).

So doing POST /transaction_imports?csv=abcd is expected to produce one record if we would be RESTful. But the code is supposed to be something like this:

# TransactionImportsController
def create
  result = TransactionImports.parse(params[:csv])
  flash[:notice] = result.message
  redirect_to transaction_imports_path
end

I am probably approaching the task from a wrong angle as I feel that implementation doesn't fit in tp the inherited_resources.

Could you please advise what would be the most conventional way of implementing this?

Thanks,
Dmytrii.

+1  A: 

REST/HTTP has no expectation that doing POST will only create one record. That maybe the default rails behaviour, but you should not constrain your design because of that.

Darrel Miller