Here's a use case:
During the creation of a new object the user will be asked to input a parameter. The parameter will be used to perform a search to help ensure the object doesn't already exist in the system before continuing.
I'm not sure where that search procedure should be located. I could put it in middleware controller but I'm not sure if that's the most appropriate place.
Do any of you more seasoned Rails developers have any insight?
--
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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
Here's the logic:
- A user will navigate to the "new" page
- A user will be presented with an input box
- The user enters a value
- A search will be performed using AJAX
- If a search comes up with nothing a transition will occur providing the user the ability to enter the rest of the information
It's logically separate from actually creating the object.
why there is a title model ? there is no need to , the title is a field of the books table, and you only need to add a new action to the BooksController (plural for controllers), to make the new action restful add this next to the map.resources :book , :member => {:make_up_a_name => :post}
then do rake routes and checkout the new restful route you have. It even has a helper method which you can use as the href for the button that triggers the ajax, the method is make_up_a_name_book_path in this example.
--
Logically, where should the search action be placed? A model/view doesn't always have a 1-to-1 relationship. So putting a search action in the BooksController doesn't seem logical to me. I guess I don't completely understand the controller's relationship between the model/controller. Does a controller lean more towards a view or model? If it has more of a bias towards a view then it seems like a TitlesSearchController makes more sense. If it's more model based, then a TitlesController with a search action would make more sense.
true is a :get not a :post( typo maybe i was thinking :get but wrote :post), but it is a member action because only one name will be returned, note that he is checking if the is more than one book with that name if that is the case he will not allow the creation so there should never be more than one and the action will only return one record
--
One further point, the code for the search itself should probably be a
class member of the model (or possibly a named scope if it is
trivial). Call this from the controller. This keeps business logic
out of the controller.
Colin