nested-attributes

Named routes inserting a . instead of a /

旧城冷巷雨未停 提交于 2020-01-05 12:08:24
问题 I've been having trouble with named routes in rails 4 (Named route for non resource nesting). I've moved onto something else, but still struggling with the same problem of named routes for non resource urls. This is my route from rake routes : GET /messages/:id/report/:reply_token(.:format) messages#report messages POST /messages(.:format) messages#create and my routes.rb resources :messages, only: [:create] do member do get 'report/:reply_token', :action => 'report'#, :as => :message end end

Rails nested attributes - does not create parent

99封情书 提交于 2020-01-05 04:38:15
问题 I have the following models: class Parent has_many :cars accepts_nested_attributes_for :cars end class Car belongs_to :parent validates :parent, presence: true end The controller code: def create parent = Parent.new parent.attributes = parent_params parent.save end def parent_params params.require(:parent).permit(:name, cars_attributes: [:name]) end When I try to create a Parent with Cars , the validation fails on the Cars because the Parent was not created yet. How can I make it pass

“Can't mass-assign protected attributes” with nested protected models

ⅰ亾dé卋堺 提交于 2020-01-04 01:15:32
问题 I'm having a time trying to get this nested model working. I've tried all manner of pluralization/singular, removing the attr_accessible altogether, and who knows what else. restaurant.rb: # == RESTAURANT MODEL # # Table name: restaurants # # id :integer not null, primary key # name :string(255) # created_at :datetime not null # updated_at :datetime not null # class Restaurant < ActiveRecord::Base attr_accessible :name, :job_attributes has_many :jobs has_many :users, :through => :jobs has

Has_Many Through Associations and Nested Attributes

二次信任 提交于 2020-01-03 01:53:07
问题 I'm trying to create a view allowing me to create and edit values of my joining table directly. This model is called 'hires'. I need to be able to create multiple rows in my joining table for when a child hires up to 2 books. I'm having some trouble and I suspect it's down to my associations... I have 3 models. Each Child can have 2 books: class Child < ActiveRecord::Base has_many :hires has_many :books, through: :hires end class Hire < ActiveRecord::Base belongs_to :book belongs_to :child

Rails validations are not being run on nested model

自闭症网瘾萝莉.ら 提交于 2020-01-02 08:58:07
问题 I'm on Rails 3.2.8 and Ruby 1.9.3. I'm having trouble figuring out why the validations on the nested attributes are not being run or returning any errors. When I submit the form with nothing filled in, I get errors back for the parent model (User), but not for the child model (Account). In my code below, I have a User model which has_one owned_account (Account model), and an Account model that belongs_to an owner (User model). The Account model has a text field for a subdomain string. It

Many-to-Many Nested Attributes in Rails 4 (with strong parameters)

守給你的承諾、 提交于 2020-01-01 06:46:58
问题 I have been trying to figure this one out for a few days now. I am using Rails 4 (with the updated mass assignment technique) and trying to use nested attributes with a many-to-many relationship. My record is saving to the DB but everything is nil and I'm getting an "Unpermitted parameters: school, alumnis, prospects" error in my logs. Here's what I have: referral.rb class Referral < ActiveRecord::Base belongs_to :school belongs_to :alumni belongs_to :prospect end alumni.rb class Alumni <

Ruby: Converting a nested Ruby hash to an un-nested one

久未见 提交于 2020-01-01 05:40:09
问题 Right now, I have a server call kicking back the following Ruby hash: { "id"=>"-ct", "factualId"=>"", "outOfBusiness"=>false, "publishedAt"=>"2012-03-09 11:02:01", "general"=>{ "name"=>"A Cote", "timeZone"=>"EST", "desc"=>"À Côté is a small-plates restaurant in Oakland's charming Rockridge district. Cozy tables surround large communal tables in both the main dining room and on the sunny patio to create a festive atmosphere. Small plates reflecting the best of seasonal Mediterranean cuisine

How to decorate nested attributes (associations) with Draper in Rails 3?

孤街醉人 提交于 2020-01-01 04:27:29
问题 My environment: Rails 3.2 with draper gem I'm using nested resources and having trouble figuring out where to declare the decorator. #app/controllers/users_controller.rb def show @user = UserDecorator.find(params[:id]) @items = @user.items end #app/controllers/items_controller.rb def show @item = @user.items.find(params[:id]) end I tried replacing items with ItemDecorator and it didn't work. Where should I be putting it? I know that Draper has issues with nested resources in forms, but this

simple_fields_for not showing up [rails 4]

大兔子大兔子 提交于 2020-01-01 04:18:28
问题 Im trying to create two hidden fields, and one shows up no problem, but the other that comes from the nested form does not product.rb class Product < ActiveRecord::Base has_many :product_options, dependent: :destroy accepts_nested_attributes_for :product_options, allow_destroy: true, :reject_if => proc { |x| x[:option_name].blank? } belongs_to :user end product_option.rb class ProductOption < ActiveRecord::Base belongs_to :product end products_controller.rb class ProductsController <

Rails - How to manage nested attributes without using accepts_nested_attributes_for?

放肆的年华 提交于 2020-01-01 03:15:15
问题 My problem is I've run into limitations of accepts_nested_attributes_for, so I need to figure out how to replicate that functionality on my own in order to have more flexibility. (See below for exactly what's hanging me up.) So my question is: What should my form, controller and models look like if I want to mimmic and augment accepts_nested_attributes_for? The real trick is I need to be able to update both existing AND new models with existing associations/attributes. I'm building an app