nested-resources

nested routes and form_for and models using has_one and belongs_to

纵饮孤独 提交于 2019-11-30 22:09:16
How to map out has_one model with nested routes and how to add a form_for for /localhost:3000/users/1/profile/new,html.erb following RESTful database? User has one Profile. Models class Profile < ActiveRecord::Base attr_accessible :name, :surname belongs_to :user end class User < ActiveRecord::Base attr_accessible :email, :email_confirmation, :password, :password_confirmation has_secure_password has_one :profile, dependent: :destroy end resources :users do resources :profiles (note: has_one profile) resources :progress_charts resources :calories_journals end views/profiles/new.html.erb <h1

Improperly configured nested resource using HyperlinkedModelSerializer

你离开我真会死。 提交于 2019-11-29 11:17:17
I have chosen the Django REST Framework and drf-nested-routers to build an API for Products and ProductReports . Here are the relevant classes: # models.py from django.db import models class Product(models.Model): created_at = models.DateTimeField(auto_now_add=True) class ProductReport(models.Model): user_name = models.CharField(max_length=256, blank=False) created_at = models.DateTimeField(auto_now_add=True) product = models.ForeignKey('Product', default=1) ... # serializers.py from rest_framework import serializers from models import Product, ProductReport class ProductSerializer(serializers

Rails - link_to, routes and nested resources

假如想象 提交于 2019-11-27 18:46:50
As my understanding on nested resources, on edge Rails, should not link_to 'User posts', @user.posts point to /users/:id/posts ? The routes.rb file contains map.resources :users, :has_many => :posts If this is not the default behavior, can it be accomplished doing something else? Along the same lines as Rishav: link_to "User Posts", [@user, :posts] Here's an explanation from my blog . Really early on in Rails, you would write routes like this: redirect_to :controller => "posts", :action => "show", :id => @post.id What this would do is dutifully redirect to the show action inside the

Rails - link_to, routes and nested resources

試著忘記壹切 提交于 2019-11-26 22:43:28
问题 As my understanding on nested resources, on edge Rails, should not link_to 'User posts', @user.posts point to /users/:id/posts ? The routes.rb file contains map.resources :users, :has_many => :posts If this is not the default behavior, can it be accomplished doing something else? 回答1: Along the same lines as Rishav: link_to "User Posts", [@user, :posts] Here's an explanation from my blog. Really early on in Rails, you would write routes like this: redirect_to :controller => "posts", :action =

REST Complex/Composite/Nested Resources [closed]

落花浮王杯 提交于 2019-11-26 16:51:31
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 sorts of properties on it like author , issue number , date , etc. A comic book also has a list of 1..n covers. These covers are complex objects. They contain a lot of information about the cover: the artist, a date, and even a base 64 encoded image of the cover. For a GET on ComicBook I could just return the comic,