Customer has many old documents(just some scanning pictures) and want
to store them into computer,we need to input the doc and relate them
to the existing authors in DB.
Key works: document;author
UI of document input page:
left side is the document input form
right side is the author search form
How should i arrange the code to deal with it.
I have 2 solutions, but i do not like them all! I think maybe i have
some misunderstanding of restful!
let the document handles them all, put the current page under folder
“views/documents”, make the author search form a partial template and
locate it under folder “views/documents” too, put the search_author
method in DocumentsController.this really works,but it break the REST
rules, how could i write the url for search_author method?
I think the search_author method should be write in
AuthorsController.If I do this, i can not get the search result
@authors from AuthorsController.
It seem that the document belongs to the author. so i use the nested
resources and add this line in route.rb
but this require that every operation on document should under a given
author, the “action” attribute of document form should be like this
“authors/2/documents”, but I do not know the author until the client
side user select one from the search result, it happens at client
I really confused about this and hope for your suggestion!
AFAIK the RESTful part is unrelated to the view part.
REST should deal with resources only, so:
/documents should return an index of all docs,
/authors should return an index of all of them,
then an association should be created when POSTing to /authors/
It should be usable without defining any view.
Afterwards, on top of that, build the view.
As you know, the document create page contains the search_author Form
in the right side. And the question is where should i locate the
If at DocumentsController, how could i write the url for
If at AuthorsController, how could i connect the AuthorsController
with the view of DocumentsController?
On 12ÔÂ6ÈÕ, ÉÏÎç12Ê±14·Ö, Klaus P. [email protected]
I would give a try at this:
For resources in routes.rb:
map.resources :authors, :has_many => :documents
So, documents should be accessible by themselves or as sub-resources
For controllers, both authors and documents should return an index of
all of them because you want to pair them up.
Or, try using :collection in routes.rb to GET only :unassigned
documents (thinking aloud here).
Finally, for your Documents view, use Ajax to make a RESTful call to
all available Authors and populate a listbox.
And when you Submit the form with paired-up Authors and Documents,
make it an Ajax POST to authors/auth_id/documents with param doc_id.
You’ll have to manage also updates and deletes.
This was just a plan, I’d like to know if it can work this way.