Home > ruby on rails > Rails routes for self nested models

Rails routes for self nested models

January 15Hits:1
Advertisement

In my rails app I have a Task model. In my app, my tasks can have substasks and so on. Since my subtasks are tasks with only a parent task, I did a self-nested model such as

class Task < ActiveRecord::Base   ## Self Join   has_many :subtasks, class_name: "Task",   foreign_key: "parent_task_id"    belongs_to :parent_task, class_name: "Task"   ## end 

I have now a trouble making routes for this model.

I naively thought that it would be that simple. Here it is:

resources :tasks do   resources :tasks end 

The result I try to acheive is by going to this url : "/tasks/1/tasks" is that I can render (by the way, in all my controllers I curently render in JSON not using views) the tasks that have as parent_task_id 1.

Hope you understand my request.

Thanks in advance ;)

Related Articles

  • Rails routes for self nested modelsJanuary 15

    In my rails app I have a Task model. In my app, my tasks can have substasks and so on. Since my subtasks are tasks with only a parent task, I did a self-nested model such as class Task < ActiveRecord::Base ## Self Join has_many :subtasks, class_name:

  • Rails - Why does my nested model form not require 'accepts_nested_attributes_for'February 9

    I have two models item and user_item. Item has many user_items and user_items belongs to item. I have a form where a user can create a new item. In the form a user should include a picture. The name, description, and tags get saved to a new item obje

  • rails and faker with nested model attributesFebruary 17

    I'm trying to populate my development postgres database with some objects that accepts nested attributes. I can't figure out how I should pass in the nested params. I tried with hash and array as well, but couldn't pull it off. Different error messag

  • Rails nested models and virtual attribute initializationJanuary 27

    I have a problem understanding how are attributes "sent" to nested model(s), and if is possible to do this for model with virtual attrubute too. I have three models: class User < ActiveRecord::Base ... has_and_belongs_to_many :clearancegoods

  • rails with most nested models and cocoon gem;

    rails with most nested models and cocoon gem;February 16

    I have a rails4 app with nested model form. There is a product model that has_many product_features, has_many product_usecases and has_many product_competitors. Everything works fine except when I load the page only the first nested model (product_fe

  • PHP MVC class with controller and nested model

    PHP MVC class with controller and nested modelNovember 26

    I had asked a first question about this class a while ago and got a few answers here which made me rewrite it completely. I removed all statics and globals, added my variables as arguments for the constructor, and pass them again as reference through

  • Knockout JS Mapping fromJS nested modelsJanuary 27

    I am having trouble understanding how to work with Knockout JS Mapping Plugin. I have some nested models (as seen below) and what I am currently doing is just using the ko.mapping.fromJS() in the parent model. What I am noticing is that computed valu

  • Point domain to rails routeJune 5

    This might not be possible, but I have a nginx server running with one domain x.com, and I have y.com that's pointing to the same server, but I would like that domain to end up running a rails route. So x.com runs /, and y.com runs x.com/2/ - not a r

  • Nested Iteration with model builder - using nested models

    Nested Iteration with model builder - using nested modelsSeptember 7

    I'm new to using model builder and have to do a nested iteration (for every month I have to iterate through 6 parameters). I am thinking of doing that by using nested models. One model doing the interation through monthes and then providing the curre

  • Problem validating parent model with nested models in modelbuilder

    Problem validating parent model with nested models in modelbuilderMarch 24

    I have a parent model with several nested models. I'm having trouble getting the parent model to validate. The issue is with sub model 4. The two screenshots are of the parent model and sub model 4. The output from sub model 3 feeds into parameter "M

  • Using global parameters in nested models of ModelBuilder?October 22

    I have a model that consists of two nested models and various parameters. There are two parameters that are common to all of the models (including the overall "grand" model). The common parameters are in-line variables and serve to assign unique

  • Passenger issue with Rails routesMay 20

    I have been tasked with getting a Rails 2.3.14 app running with Phusion Passenger 5.0.7 standalone in FreeBSD 9. Setup is all complete and done, the issue I am facing is Passenger doesn't seem to recognize Rails routes. If I place index.html inside t

  • Creating Instance of Nested model inside parent controllerJanuary 18

    I would like to know if it is possible to create an instance of a nested model inside the parents controller. Let me explain. I have a model called Museum and another model called Museumimage. Museumimage has only one field which is an attachment, ma

  • Understanding rails routing that include (= ) and (:as)February 10

    While reading about rails routing I found routing that include =>. But I don't understnad what it means. Also I found some routing example with :as. It would be nice if someone explained a little bit about it. I have read rails guide but still I am n

  • Trying to update nested model first on before_saveFebruary 11

    I am calculating :price in my nested item model in order to map it in my invoice model. The problem is that the before_save in the invoice model is being called first and I want it to be called after the before_save in the nesteditem model Any ideas

  • How to get the current user id in the Rails router (routes.rb)February 12

    Is it possible to get the user ID of the current user in the Ruby on Rails router (app/config/routes.rb)? --------------Solutions------------- Create an action in your posts controller 'user_post_index',then you can try this, get 'users/:id/posts', t

  • Is there a way to disallow a path in Rails routes?February 12

    I have a development and production version of the frontend/API. The production version is in the folder public/articles/... and the development version is in public/articles/development/.... It contains javascript, css and other assets. In my Rails

  • Before validation on nested modelJanuary 9

    I have a nested model items and I am trying to multiply two columns together cost and quantity to set the last column price. I need to set the column price before the form is saved and i need to also validate the model. The before_validation call bac

  • Creating nested models in Rails 4 forum appJanuary 31

    Hello I am making a Forum application in Rails 4. It can have numerous forums, each with numerous topics. Each topic can have many posts. When creating a new topic, one must also create the initial post, much like Stack Overflow itself. Therefore, I

  • Ruby on rails. Form for a nested model in a different viewFebruary 13

    I've been battling this for a while now and I can't figure it out. I have a user model using devise. Users can upload songs, and add youtube videos etc.. I'm trying to let users add/delete songs and videos from the devise edit registrations view. Vid

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.525 s.