Backgroup: 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 Problem: 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! Solution1: 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. Solution2: It seem that the document belongs to the author. so i use the nested resources and add this line in route.rb map.resources :authors,:has_many=>:documents 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 side. I really confused about this and hope for your suggestion! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Klaus Pieslinger
2008-Dec-05 16:14 UTC
Re: 2 forms in one page,how to arrange the code and do it restful?
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/ id_from_right_pane/documents/id_from_left_pane. It should be usable without defining any view. Afterwards, on top of that, build the view. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
乱翻字典
2008-Dec-06 10:42 UTC
Re: 2 forms in one page,how to arrange the code and do it restful?
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 "search_author" method? If at DocumentsController, how could i write the url for "search_author" restful? If at AuthorsController, how could i connect the AuthorsController with the view of DocumentsController? On 12月6日, 上午12时14分, Klaus Pieslinger <klaus.pieslin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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/ > id_from_right_pane/documents/id_from_left_pane. > It should be usable without defining any view. > Afterwards, on top of that, build the view.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Klaus Pieslinger
2008-Dec-08 19:37 UTC
Re: 2 forms in one page,how to arrange the code and do it restful?
I would give a try at this: For resources in routes.rb: map.resources :authors map.resources :documents map.resources :authors, :has_many => :documents So, documents should be accessible by themselves or as sub-resources of authors. 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. Cheers! On Dec 6, 7:42 am, 乱翻字典 <maerd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > "search_author" method? > If at DocumentsController, how could i write the url for > "search_author"restful? > If at AuthorsController, how could i connect the AuthorsController > with the view of DocumentsController? > > On 12月6日, 上午12时14分,KlausPieslinger <klaus.pieslin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > AFAIK theRESTfulpart 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/ > > id_from_right_pane/documents/id_from_left_pane. > > It should be usable without defining any view. > > Afterwards, on top of that, build the view.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- WebServices & controllers
- Resotolog-1.2 - RESTful blog example (was Community request - can someone show me REST? )
- gluster-rest, a RESTful web api server for gluster
- Restful routes, not repeating yourself and non-standard rest actions best practices
- Is Ezra''s RESTful recipe needed anymore?