简体   繁体   中英

Integrating multiple models into one view

I'm trying to build a car dealership web app and I want to optimize testing by combining models into one view. Specifically, the main page is a dropdown list where the user enters his postal code and a car brand (toyota, ford, etc.). I want this to route to /dealerships/search.html.erb. What I want to show on this page is Dealership location, phone number and a link to the dealership home page. All car brands have the same attributes and I want to have one view, where the dealership table is filled with (id: 1 name: toyota, id:2, name: ford, etc.) and each of the toyota table, ford table have a dealership_id attribute. I'm still very confused as to how to implement this. I would really appreciate all suggestions and guidance in the right direction. Also, is this advisable, and is there a way to not have so many controllers and so many models at all. I just want to have the one aggregated view and multiple tables that can be called upon depending on user selection.

I would say it is possible but not advisable. Rails is based on MVC and you should do logically different tasks in different actions and according to design in different controllers if required. I understand that in beginning it feels like a lot of work but believe me once you start understanding the whole thing it would be more easy to handle and to work with. If you put all the things at once place it will become tough to manage in future.

As far as your projected need are concerned you can make different controllers and actions and call them in the required view where ever wanted. Rails give exception support for thus type of calling and it will all run good and in the right way. I would suggest you to develop this in the suggested way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM