nested-resources

How to save a nested resource in ActiveRecord using a single form (Ruby on Rails 5)

☆樱花仙子☆ 提交于 2021-01-04 09:14:15
问题 I have two entities with a many-to-one relationship. User has many Addresses. When creating a User I want the form to also create a single Address. The entities are nested. Approach 1: The code below works, but only saves the User, no associated Address. Reading around, I thought that the accepts_nested_attributes_for would automatically save the address. I'm not sure, but it may be that this isn't working because the parameters I'm getting into the Controller don't actually appear to be

Rails 3.1 has_one nested resource: routing not generating “all” paths

拥有回忆 提交于 2020-01-31 19:33:05
问题 I have a has_one relation: # supplier.rb has_one :presentation ... # presentation.rb belongs_to :supplier ... and the folowing nested routes for them: # routes.rb resources :suppliers do resource :presentation end running rake routes gives: supplier_presentation POST ... {:action=>"create", :controller=>"presentations"} new_supplier_presentation GET ... {:action=>"new", :controller=>"presentations"} edit_supplier_presentation GET ... {:action=>"edit", :controller=>"presentations"} GET ... {

Improperly configured nested resource using HyperlinkedModelSerializer

会有一股神秘感。 提交于 2020-01-28 09:54:13
问题 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

Improperly configured nested resource using HyperlinkedModelSerializer

青春壹個敷衍的年華 提交于 2020-01-28 09:53:12
问题 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

Rails :include doesn't include

邮差的信 提交于 2020-01-06 08:18:36
问题 My models: class Contact < ActiveRecord::Base has_many :addresses has_many :emails has_many :websites accepts_nested_attributes_for :addresses, :emails, :websites attr_accessible :prefix, :first_name, :middle_name, :last_name, :suffix, :nickname, :organization, :job_title, :department, :birthday, :emails_attributes end class Email < ActiveRecord::Base belongs_to :contact validates_presence_of :account validates_format_of :account, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on =>

Rails Nested Singular Resource Routing

可紊 提交于 2020-01-01 07:37:06
问题 I have a simple User model with a singular nested Profile resource so in my routes.rb I have: resources :users do resource :profile, :only => [:edit, :update, :show] end This generates the expected routes: edit_user_profile GET /users/:user_id/profile/edit(.:format) {:action=>"edit", :controller=>"profiles"} user_profile GET /users/:user_id/profile(.:format) {:action=>"show", :controller=>"profiles"} user_profile PUT /users/:user_id/profile(.:format) {:action=>"update", :controller=>"profiles

Does anybody have any tips for managing polymorphic nested resources in Rails 3?

此生再无相见时 提交于 2020-01-01 03:10:52
问题 In config/routes.rb: resources :posts do resources :comments end resources :pictures do resources :comments end I would like to allow for more things to be commented on as well. I'm currently using mongoid (mongomapper isn't as compatible with Rails 3 yet as I would like), and comments are an embedded resource (mongoid can't yet handle polymorphic relational resources), which means that I do need the parent resource in order to find the comment. Are there any elegant ways to handle some of

How to Link PGSeaerch results to Index Page in Nested Resources?

ぐ巨炮叔叔 提交于 2019-12-30 11:52:37
问题 I finally figured out how to implement pg_search's multisearch feature. But I'm having trouble making a usable search page that displays links back to the appropriate nested pages. How can I pass the proper id so I could link to the nested views. So something like this link_to myapp.com/artists/1/albums So far I get this error(i cant seem to pass the artist id) No route matches {:controller=>"albums", :artists=>nil} New to Rails Please help :) CONTROLLERS class ResultsController <

How can I mass assign across 2 models when importing a csv file?

自闭症网瘾萝莉.ら 提交于 2019-12-25 14:49:32
问题 I can import a CSV file and create a new object (listing in this case) using the attributes from a single model. I put this in the Listing model accepts_nested_attributes_for :address where address is an associated model (address has many listings, listing belongs to address). I thought I'd then be able to mass assign attributes from the address model also when importing the CSV file but I get the error: Can't mass-assign protected attributes: unit_number where unit_number in one of the

How can I mass assign across 2 models when importing a csv file?

一笑奈何 提交于 2019-12-25 14:49:09
问题 I can import a CSV file and create a new object (listing in this case) using the attributes from a single model. I put this in the Listing model accepts_nested_attributes_for :address where address is an associated model (address has many listings, listing belongs to address). I thought I'd then be able to mass assign attributes from the address model also when importing the CSV file but I get the error: Can't mass-assign protected attributes: unit_number where unit_number in one of the