Hi, So finally I have also decided to roll my engines on Rails. But I am kind of stuck in a situation. I understand that for every model there is a controller class. This controller class has cirtain set of methods where each method defines cirtain action to be performed. And each of this action renders cirtain UI. [The background] Now let say I have a object "Car". Apart from having basic attributes like car name, model, etc etc, tt has a list of "parts" that a car has. This essentially means i have two models (or tables in db) "Car" and "Part" and "Cars_Controller" and "Parts_COntroller". [The Problem] Now I want to develop an edit interface for this scenario. The edit interface has two tabs "General Car Details" and "Car Parts". Now I understand that when I select to "edit" a car. This will take me two first edit screen where I will see "General Car Details" (as default selected tab). The problem is that I couldn''t figure out how do I move to next tab which is "Parts" tab. Should I create a new action something like "EditCarParts" or is there any way to define sub action for edit action or something liek that? My second question is by default an ection is binded to a citan view. For example "Edit" action is binded to "Edit.rhtml" page. How can i override this? -- Posted via http://www.ruby-forum.com/.
On Saturday 08 April 2006 12:01, Dipesh Batheja wrote:> Hi, > So finally I have also decided to roll my engines on Rails. But I am > kind of stuck in a situation. I understand that for every model there is > a controller class. This controller class has cirtain set of methods > where each method defines cirtain action to be performed. And each of > this action renders cirtain UI. > > [The background] > Now let say I have a object "Car". Apart from having basic attributes > like car name, model, etc etc, tt has a list of "parts" that a car has. > This essentially means i have two models (or tables in db) "Car" and > "Part" and "Cars_Controller" and "Parts_COntroller". > > [The Problem] > Now I want to develop an edit interface for this scenario. The edit > interface has two tabs "General Car Details" and "Car Parts". > Now I understand that when I select to "edit" a car. This will take me > two first edit screen where I will see "General Car Details" (as default > selected tab). The problem is that I couldn''t figure out how do I move > to next tab which is "Parts" tab. Should I create a new action something > like "EditCarParts" or is there any way to define sub action for edit > action or something liek that? > > My second question is by default an ection is binded to a citan view. > For example "Edit" action is binded to "Edit.rhtml" page. How can i > override this? >Your first question can be answered by knowing that you can let a link call any controller or action. You can easily have a link in your car view, like so: link_to("edit this part", {:controller => "parts", :action => "edit", :id => part.id}) Also, you don''t need one controller for every model. You could easily have one controller for your car, with which you can edit parts as well. There _is_ one controller for every view. In this case however, I would make a seperate controller for your parts, because I would imagine you want to edit parts individually. Editing the parts of a car would only involve assinging parts to cars, which should go in the view and controller of a car, because it is data of a car. And about overriding the rhtml names, I don''t believe you can, nor can I think of why.
Dipesh Batheja wrote:> Hi, > So finally I have also decided to roll my engines on Rails. But I am > kind of stuck in a situation. I understand that for every model there is > a controller class. This controller class has cirtain set of methods > where each method defines cirtain action to be performed. And each of > this action renders cirtain UI. > > [The background] > Now let say I have a object "Car". Apart from having basic attributes > like car name, model, etc etc, tt has a list of "parts" that a car has. > This essentially means i have two models (or tables in db) "Car" and > "Part" and "Cars_Controller" and "Parts_COntroller". > > [The Problem] > Now I want to develop an edit interface for this scenario. The edit > interface has two tabs "General Car Details" and "Car Parts". > Now I understand that when I select to "edit" a car. This will take me > two first edit screen where I will see "General Car Details" (as default > selected tab). The problem is that I couldn''t figure out how do I move > to next tab which is "Parts" tab. Should I create a new action something > like "EditCarParts" or is there any way to define sub action for edit > action or something liek that? > > My second question is by default an ection is binded to a citan view. > For example "Edit" action is binded to "Edit.rhtml" page. How can i > override this? >For the second question, using render :action=>''name_of_rhtml''
<posted & mailed> On Saturday 08 April 2006 08:35, Anocha Yimsiriwattana wrote:> For the second question, using > > render :action=>''name_of_rhtml''Oh yeah, I forgot :)
Wiebe Cazemier wrote:> <posted & mailed> > > On Saturday 08 April 2006 08:35, Anocha Yimsiriwattana wrote: >> For the second question, using >> >> render :action=>''name_of_rhtml'' > > Oh yeah, I forgot :)Thank you Anocha and Wiebe, but still have doubts in first question. Firstly i just want to display list of all the parts associated with a car when i edit that car''s details. Now, the url to edit the car could look something like /CarApp/Cars/edit/5, which means i am editing the car number 5. Can''t we have something like /CarApp/Cars/edit/5/parts which will mean I am seeing list of all the parts associated with car number 5 in edit mode. How do i organise my code to get this kind of URL? -- Posted via http://www.ruby-forum.com/.
I suggest taking a look at routes. You can make your URLs look however you want with those. You can also use modules to group your models in folders. You can use routes and modules together to make your urls more pleasing. so instead of /cars/ /parts/ you could have /car/ /car/parts and if you really want to put the effort in, you can do /car/5/parts But you need t o read the stuff that''s out there to really understand it all. Start with a search of the wiki and read through the agile book. I am confident that if you know Rails well enough you can pretty much do anything with it. On 4/8/06, Dipesh Batheja <dipesh_batheja@yahoo.com> wrote:> > Wiebe Cazemier wrote: > > <posted & mailed> > > > > On Saturday 08 April 2006 08:35, Anocha Yimsiriwattana wrote: > >> For the second question, using > >> > >> render :action=>''name_of_rhtml'' > > > > Oh yeah, I forgot :) > > Thank you Anocha and Wiebe, but still have doubts in first question. > Firstly i just want to display list of all the parts associated with a > car when i edit that car''s details. Now, the url to edit the car could > look something like /CarApp/Cars/edit/5, which means i am editing the > car number 5. Can''t we have something like /CarApp/Cars/edit/5/parts > which will mean I am seeing list of all the parts associated with car > number 5 in edit mode. How do i organise my code to get this kind of > URL? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060408/656c5dfa/attachment-0001.html