nested-attributes

Rails 4 Nested form with devise logs me out on update

坚强是说给别人听的谎言 提交于 2019-12-11 11:37:25
问题 I have a nested form with the parent model built with devise and the child model without devise. I'm working on the edit form which has the user model fields and nested inside them expert model fields. The update/save works but logs me out and gives me an error saying "You need to sign in or sign up before continuing" When I sign back in I see that the fields have been updated correctly. I would like it to not sign me out and show me the updated Edit page upon submitting the form. User model

How do I make nested_attributes work in Rails3?

前提是你 提交于 2019-12-11 10:36:44
问题 Here's my user model: class User < ActiveRecord::Base has_one :teacher, :dependent => :destroy accepts_nested_attributes_for :teacher, :allow_destroy => true attr_accessible :email, :password, :password_confirmation, :remember_me, :teacher_attributes end Here's my teacher model: class Teacher < ActiveRecord::Base belongs_to :user attr_accessible :user_id, :first_name, :last_name validates_presence_of :user_id, :first_name, :last_name end Here's my form: <%= form_for(@user, :url =>

Rails 5 multiple nested attributes no Routing Error uninitialized constant Sites

有些话、适合烂在心里 提交于 2019-12-11 08:56:14
问题 Hello I have a little app with three nested models Client, Site and Damper. When I add a client or client_site all is fine... but when i come to add a damper I get Routing Error uninitialized constant Sites in the console Started GET "/clients/1/sites/1/dampers/new" for my ip at 2018-10-26 18:05:29 +1000 ActionController::RoutingError (uninitialized constant Sites): app/controllers/clients/sites/dampers_controller.rb:1:in `<main>' Routes resources :clients do resources :sites, controller:

Rails 5 - exclude specific instances from edit path on parent controller

心不动则不痛 提交于 2019-12-11 08:34:55
问题 I have models in my Rails 5 app for User, Proposal and Potential. Users create Proposals which they themselves and others can then create comments on. The associations between models are: User has_many :proposals, dependent: :destroy has_many :potentials Proposal belongs_to :user has_many :potentials, inverse_of: :proposal accepts_nested_attributes_for :potentials, reject_if: :all_blank, allow_destroy: true Potential belongs_to :proposal, inverse_of: :potentials belongs_to :user In my routes

Named route for non resource nesting

旧巷老猫 提交于 2019-12-11 08:24:02
问题 I'm trying to generate a link for a user to click to confirm their account. I'm wanting this: /users/:id/confirm/:code I've got this in my routes file: resources :users do member do get 'confirm/:confirmation_code', :action => 'confirm' end end I've tried: user_confirm_path(@user, @confirmation_code) confirm_user_path(@confirmation_code, @user) and many others but can't seem to get the right one. I guess I could always generate the link url myself but that doesn't seem the rails way. This is

Merge Nested Attributes

南楼画角 提交于 2019-12-11 04:16:55
问题 I have a sample using post, comments and author models. Please see my full requirement from the following thread Nested routes and CRUD operations with additional values for assciation in Rails Here i need to create one comment when a post is created. I used nested attributes and working fine. But my issue is i don't want all attributes from the user. Some attributes needs to be added internally. I can merge if the attributes not having nested attributes. But merge not worked for nested

Use a dict to access nested instances of classes in Python

狂风中的少年 提交于 2019-12-11 03:47:10
问题 I'm trying to define an attribute in a nested class and then access it later using a string or maybe a list of strings. Here's code for what I'm trying to do class MyNestedClass(object): def __init__(self): self.att1 = 5. class MyClass(object): def __init__(self): self.my_nested_inst = MyNestedClass() my_inst = MyClass() I want to change the value of my_inst.my_nested_inst.att1 when all I have is a list like this: my_list = ['my_inst','my_nested_inst','att1'] . If I use this: vars(vars(vars()

Update nested_attributes by default

China☆狼群 提交于 2019-12-11 01:25:27
问题 I try to update iproduction, a nested form from production and I have an error of params with this line : "wrong number of arguments (0 for 1)" @production.update.iproductions_attributes(cow_id: @cow) My create action production: def create @production = @ranch.productions.create(production_params) @production.update(date: Date.today) @cows = @ranch.cows @cow = Cow.find_by(id: params[:id]) @production.update.iproductions_attributes(cow_id: @cow) respond_to do |format| if @production.save

Nested attributes in Ruby on Rails not saving

a 夏天 提交于 2019-12-10 23:53:22
问题 I'll preface this by saying I've looked at the following answers and still have not hit a solution that works (however, given the possibility I might have overlooked something, I'm including them for reference): Ruby on Rails - Not saving User - Nested Attributes and Nested Forms Nested Attributes in ruby on rails Ruby on Rails nested attributes not saving into database? Nested attributes not saving in database? Does not display values - Ruby on Rails Description of problem: I have a form

Rails 4 has_many nested_attributes to replace all

筅森魡賤 提交于 2019-12-10 21:46:22
问题 I want to use nested_attributes to replace all my old associated objects by the new ones. How is the best way to do that? If I use the code below, every time I update my main object with nested_attributes, new objects associated are created. accepts_nested_attributes_for :days Edit I´ve got it with the before_validation callback below: def replace_days db_days = days.where('id IS NOT NULL') all_days = days all_days -= db_days self.days = all_days end The problem with that is my unique