ruby on rails - Automatically add parent model id in nested resources -


With nested resource routes in Rail 3, such as the following:

  Resources: Magazines resources To: Ads ending   

are helpful, such as magazine_ad_path is defined, for which I have to pass both a magazine and an advertisement, which I have One reference to the ad is inconvenient:

  journal_pad_path (@ ad.magazine, @ad)   

What a good way to set a ad_path Confirms Accessories that @ad takes and magazine fair dates back including ID? (This will also allow the use of link_to @ad , redirect_to @ad , etc., which will automatically call ad_path assistant model Class.)

Shallow routing looks like what you are looking for. You can execute a shallow nest victim as:

  Resources: Magazines do so shallow resources: the ad ends   

OR

  Resources: Magazines, shallow = & gt; Correct the resources: Ad End   

Only index and new actions are nested

Using nested resources, goes to generate long URLs, for shallow nests The hunt helps to remove parts (which includes the basic resource route), which are not necessary for certain tasks (because one of the basic resources can be obtained from one, maintaining a child's record. To eat).

Comments