nested-resources

HTTP POST request sent via curl against REST server looses JSON parameters

两盒软妹~` 提交于 2019-12-25 05:26:23
问题 I created a REST server with Rails that manages Users and associated Comments . Here is the routes configuration. resources :users do resources :comments end In the controller I only need actions to query and create Comments . The exchange format is JSON. class CommentsController < ApplicationController def index @user = User.find(params[:user_id]) @comments = @user.comments respond_to do |format| format.html # index.html.erb format.json { render json: @comments } end end def create @user =

Rails 4 x paper_trail: keep track of versions after item is destroyed

六月ゝ 毕业季﹏ 提交于 2019-12-24 12:41:34
问题 This is a follow up question on Rails 4 x paper_trail: filter versions by item_id with nested resources. ————— CONTEXT FROM PREVIOUS QUESTION In my Rails 4 app, I have the following models: class User < ActiveRecord::Base has_many :administrations, dependent: :destroy has_many :calendars, through: :administrations end class Administration < ActiveRecord::Base belongs_to :user belongs_to :calendar end class Calendar < ActiveRecord::Base has_many :administrations, dependent: :destroy has_many

Link_to Routing Issue With Nested Resources

旧巷老猫 提交于 2019-12-23 20:21:45
问题 I have two models Jobs and Questions. A job has many questions and questions belong to a job. I've set up the resources in the model, as well as the routes. I am having an issue trying to link_to the Show method of the questions controller on the questions#index page. My rake routes say that the path should be job_question_path with the two necessary :id's being :job_id and :id , so I tried: <td><%= link_to 'Show', job_question_path(@job, question) %></td> and got the error: No route matches

How to nest collection routes?

妖精的绣舞 提交于 2019-12-22 18:24:08
问题 I use the following routes configuration in a Rails 3 application. # config/routes.rb MyApp::Application.routes.draw do resources :products do get 'statistics', on: :collection, controller: "statistics", action: "index" end end The StatisticController has two simple methods: # app/controllers/statistics_controller.rb class StatisticsController < ApplicationController def index @statistics = Statistic.chronologic render json: @statistics end def latest @statistic = Statistic.latest render json

“Previous post” and “Next post” link in Show View (Nested Resources)

岁酱吖の 提交于 2019-12-21 06:06:40
问题 In my Application I want to add a "Previous Article" and a "Next Article" link in the bottom of my Article Show View. This is what I have so far but I get this error: undefined method `article_path' for #<#<Class:0x007fd7c581af48>:0x007fd7cb8e5968> I know the path must look like this (but i am having a hard time implementing it) myapp/users/1/article/1 New to Rail Please Help ... ROUTES resources users do resources articles end MODELS class User < ActiveRecord::Base attr_accessible :name,

REST Complex/Composite/Nested Resources [closed]

落爺英雄遲暮 提交于 2019-12-17 03:44:47
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . I'm trying to wrap my head around the best way to address concepts in a REST based API. Flat resources that don't contain other resources are no problem. Where I'm running into trouble are the complex resources. For instance, I have a resource for a comic book. ComicBook has all

In rails routes, nested resources is causing white screen

自闭症网瘾萝莉.ら 提交于 2019-12-13 23:55:59
问题 I have two models: Schedule and Project. Schedule belongs_To Project and Project has_one schedule. The routes for schedule and Project are nested like this: get 'projects/current', to: 'projects#show_current', as: :current_freelancer_projects resources :projects do resources :schedules end When I run rake routes, it says the path to make a new schedule is: new_project_schedule GET /projects/:project_id/schedules/new(.:format) The problem is, when I include a link to new_project_Schedule on a

Rails 3 Routing Error with Nested Resources

对着背影说爱祢 提交于 2019-12-13 21:22:12
问题 In my Rails application, there are many games, and each game has it's own set of leaderboards. It makes sense then, to have the leaderboards nested in the game, so you can only get to a leaderboard through a game. I setup my routes.rb file as such (the important part): resources :games do resources :leaderboards end So then I updated my controller so it would get the appropriate game from the game_id passed in, and grab the leaderboard information from that. However, my issues comes from my

How to RESTfully support the creation of a resource which is a collection of other resources and avoiding HTTP timeouts due to DB creation?

独自空忆成欢 提交于 2019-12-13 01:03:07
问题 In my application I have the concept of a Draw, and that Draw has to always be contained within an Order. A Draw has a set of attributes: background_color, font_size, ... Quoting the famous REST thesis: Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on. So, my collection of other resources here would be an Order. An Order is a set

Rails 4 x paper_trail: filter versions by item_id with nested resources

我们两清 提交于 2019-12-12 18:28:24
问题 In my Rails 4 app, I have the following models: class User < ActiveRecord::Base has_many :administrations, dependent: :destroy has_many :calendars, through: :administrations end class Administration < ActiveRecord::Base belongs_to :user belongs_to :calendar end class Calendar < ActiveRecord::Base has_many :administrations, dependent: :destroy has_many :users, through: :administrations end class Post < ActiveRecord::Base belongs_to :calendar end I installed the paper_trail gem to track changes