Menu
  • HOME
  • TAGS

How to .count nested_attribute boolean?

ruby-on-rails,ruby,boolean,nested-attributes,sidebar

You can update your Result as follows: class Result < ActiveRecord::Base # rest of the code scope :good, -> { where(good: true) } scope :good_count, -> { good.count } end Let's perform some tests in rails console: u = User.create({ user_attributes }) u.results.create(good: true) u.results.create(good: false) u.results.create(good: true) u.results.count #...

How to create nested models from API request?

ruby-on-rails,ruby,nested-attributes

In your create action, instead of this: @event.event_categories.build Try this: @event.event_categories = EventCategory.new do |ec| ec.event = @event ec.category = the_cattegory_you_want_to_specify # You need both of these as you are validating the presence of event AND category end ...

rails nested attribute do not show in form

ruby-on-rails,nested-attributes

Make sure you have student_profile_id attribute/column present in educations table. After that, as you have mentioned, you need to build educations object on student_profile as: def new @profile = current_user.build_student_profile @profile.educations.build end ...

How to Add Current_User to Nested Attribute?

ruby-on-rails,ruby,user,nested-attributes

This will hopefully guide you in the right direction This is odd to me def index @averaged_quantifieds = current_user.quantifieds.averaged @instance_quantifieds = current_user.quantifieds.instance @averaged_quantifieds = Result.all.order("date_value") @instance_quantifieds = Result.all.order("date_value") end You define both of these twice and essentially overwrite each other? If your attributes aren't showing, it doesn't have anything to...

How to display data for nested objects in a check box in Rails?

ruby-on-rails,nested-attributes

I figured it out thanks to advice from @davidwessman. What he told me was to display the html and inspect. I did and compared to the html from the edit action (the one that works). It then became clear that I needed to use the check_box_tag command instead of check_box....

Rails deeply nested resources alternative to accessing params

ruby-on-rails,nested-attributes,params,rails-routing,nested-resources

With some help I derived this answer from a bit of kobaltz answer and some other help. The alternate method would be putting the information in hidden fields and passing it to the controller <%= @event.event_questions.each do |q| %> <%= q.question %><br> <% q.event_answers.each do |a| %> <%= a.answer %>...

Finding specific database entries when using nested attributes in RoR

ruby-on-rails,ruby,nested-attributes

The undefined method on NilClass is because your instance variable @survey is nil, and when you're calling Question.where(:survey_id => @survey.id).all you're getting that error. If you're associations are set up right you should be able to run @survey.questions and not have to perform the search on Questions. That's part of...

Method to change resource attribute based on nested resource attributes

ruby-on-rails,model,nested-attributes

You can simplify your function as follows: @goal.status = @goals.tasks.map(&:complete).all? Assuming you want to know as soon as possible whether or not your goal is complete, you'll want to put this function in your Task model. You can do it as follows: def Task < ActiveRecord::Base belongs_to :goal after_save :goal_completed...

Display nested attributes together in view or index.html.erb

html,ruby-on-rails,ruby-on-rails-4,twitter-bootstrap-3,nested-attributes

You can try with includes if you have explicitly set has_many association in your Product model (assuming is is named product_images): app/controller/home_controller.rb: @products = Product.includes(:product_images) .where(product_images: { default_image: true ) .last(5) app/views/home/index.html.erb: <div class="col-md-3 col-sm-6 hero-feature"> <div class="thumbnail"> <% @products.each do |pd| %> <% pd.product_images.each do |i| %> <%= image_tag...

Rspec testing nested destroy action for follows model

ruby-on-rails-4,rspec,nested-attributes

I think the routing error was indeed due to specifying followable_id rather than article_id as implied by the comment you received. The subsequent no method error, however, was due to making that change in the factory call as well. The following is what you should try: describe '#DELETE destroy' do...

trying to add nested comments with closure_tree

ruby-on-rails,ruby,nested-attributes

You have a typo in your Comment model. Change 'DESC1' to 'DESC'

rails multiple belogs_to assignments with nested attributes

ruby-on-rails,nested-attributes,belongs-to

As I wrote in the comments, there's two ways of doing this. The first way is to add a hidden field in your subform to set the current user: = simple_nested_form_for(@issue) do |f| = f.input :title = f.fields_for(:comments) do |cf| = cf.input(:content) = cf.hidden(:user, current_user) = f.submit If you do...

Unpermitted parameters - Rails 4.1.1, Ruby 2.1.2

ruby,ruby-on-rails-4,nested-attributes,strong-parameters

The problem is this line order_row_attributes.It should be order_rows_attributes. And with the date not being permitted,try changing the date attribute to some name like order_date. This should work private def order_params params.require(:order).permit(:customer_id, :order_date, :total, :order_rows_attributes => [:description, :quantity, :price, :order_id]) end ...

Rails 4 retrieve nested attributes for display in an index.html.erb

image,ruby-on-rails-4,twitter-bootstrap-3,nested-attributes,home

You can try this: app/controller/home_controller.rb class HomeController < ApplicationController def index @products = Product.last(5) @product_ids = @products.collect(:id) @product_images = ProductImage.where(:id => @product_ids).last(5) end end app/views/home/index.html.erb <% @products.each do |pd| %> <div><%= pd.product_name %> <% end %> <% @product_images.each do |pd| %> <%= image_tag (pd.product_image(:medium)) %> <% end %> ...

nested model attributes + wicked wizard form not working

ruby-on-rails-4,simple-form,nested-attributes,wicked-gem

When you're using accepts_nested_attributes_for you must specify your attributes to whitelist them: educations_attributes and works_attributes (as shown in the API) def user_params params.require(:user).permit( :first_name, :last_name, :email, :password, :password_confirmation, :county_id, :area_id, :client, educations_attributes: [:school_name, :degree, :year_started, :year_finished], works_attributes: [:company_name, :work_title, :date_started, :date_finished] ) end ...

Create two interdependent models from one form in rails

ruby-on-rails,ruby,forms,nested-forms,nested-attributes

I think that in order for your patient form fields to show up, you need to say @user.build_patient in your new action in your UsersController. This initializes a patient that is associated with the User instance you created. In case it helps anyone else, if the relationship between patient and...

Rails nested attributes and has_many :through associations not showing fields_for

devise,nested-forms,nested-attributes

After some digging and experimentation here is how I resolved this: Models class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :roles, :dependent => :destroy, :inverse_of => :user has_many :companies, :through => :roles accepts_nested_attributes_for :roles, :limit => 1, :allow_destroy => true end class Role < ActiveRecord::Base belongs_to...

Attribute a Row, Nested Below (How to Show Proper Relationship in Table?)

ruby-on-rails,dynamic,nested-attributes

It's tricky because the data is column-wise but we need it row-wise. I'm not 100% sure I understand how the quantified data is laid out but the gist of the solution is, you need two separate loops since the heading <thead> and data <tbody> are in separate sections of a...

Rails - Nested Strong parameters

ruby-on-rails,nested-attributes,strong-parameters

use the singular profile_attributes if it's a has_one

Rails 4.1 Enum limit return in fields_for

ruby-on-rails,enums,nested-attributes,ruby-on-rails-4.1

Silly me. I can pass a second argument to the simple_fields_for which will limit the results. f.simple_fields_for :tiles, f.object.tiles.where(position: Tile.positions[:middle_column]) do |builder|...

Updating attributes of a nested model

ruby-on-rails,nested-attributes

It looks like you have the modify the model as such: accepts_nested_attributes_for :user, allow_destroy: true, update_only: true Adding the update_only: true prevents it from creating a new instance of user...

Two nested form objects

ruby-on-rails,ruby-on-rails-4,nested,nested-forms,nested-attributes

Change this line <%= w.link_to_remove "Remove attachment", class: "text-right"%> to <%= h.link_to_remove "Remove attachment", class: "text-right"%> ...

Assign parameters with strong parameters and nested models in rails 4

ruby-on-rails,forms,rails-activerecord,nested-attributes,strong-parameters

The problem, I would say, is that you are using a text_field input for category and sub_category. In order for this to work, you should use a select field and then provide another way in the UI to create categories and sub_categories. Replacing f.text_field :subcategory with (and removing the :category...

RoR: nested attributes undefined method `build

ruby-on-rails,controller,nested-attributes,fields-for

Give this a try- @cliente.build_local() instead of - @cliente.build_local ...

Error: Unpermitted parameters with nested attributes

ruby-on-rails,ruby-on-rails-4,nested-forms,nested-attributes,strong-parameters

The usual way to do the above would be Controller def new @incorporation = Incorporation.new @company = @incorporation.build_company and in your view <%= form_for @incorporation do |f| %> <div class="panel-body"> <%= f.text_field :title, input_html: { class: 'form-control' } %> <h3>TEST</h3> <%= f.fields_for :company do |company| %> <%= company.text_field :name, input_html:...

Rails Nested attributes with check_box loop

ruby-on-rails,ruby,nested-attributes

AS per your model definitions, ProviderCategory has attributes category_id and provider_id. You are getting error as: undefined method `category_id' for #<Category:0x0000010184ff60> because instead of passing instance of ProviderCategory, you have passed an instance of Category class. Notice category being passed in =f.fields_for :provider_category, category do |pl| and as there is...

Has Many Through relationship with accepts nested attributes

ruby-on-rails,associations,nested-attributes,has-many-through

Your join model name is not per Rails Naming convention. It should be called DeedTitleAbstract insted of DeedsTitleAbstracts. So fixing this class name including the database table name is probably the best thing to do instead of incorporating a workaround(shown below). The workaround for this is to supply the class_name...

Generating dynamic child rows in Rails partial

ruby-on-rails,nested-attributes,railscasts,ruby-on-rails-4.2

I wound up solving this with jQuery. Not super elegant but very effective. Basically, I just added a click handler for the + icons which built the new row and inserted it where needed (basically just hacked out the jQuery necessary to replicate the HTML produced by Rails). In case...

undefined method `each' for #

ruby-on-rails,ruby-on-rails-4,carrierwave,image-uploading,nested-attributes

You are trying to iterate through an array of images but your params only have one image so the fix is replace: params[:images][:image].each do |i| @image = @service.images.create!(:image => i, :imageable_id => @service.id, :image_type => params[i][:image_type]) end with @image = @service.images.create!(:image => params[:images][:image], :imageable_id => @service.id, :image_type => params[:images][:image_type]) ...

Change naming of model_attributes for just model

ruby-on-rails,nested-attributes

The easiest would be to just modify the hash, like this: params["pages_attributes"] = params.delete("pages") You could put that in a before_action to ensure it happens for all the actions in the specific controller....

Undefined Nested Attributes for nil:NilClass

ruby-on-rails,ruby,nested-attributes,cocoon-gem

In your view you iterate with: @quantifieds.results.each do |result| In your index action you got @quantified = Result.order("date_value").all I guess it should be @quantifieds = Result.order("date_value").all ...

Add Multiple Nested Attributes through checkboxes Rails 4 (maybe with multiple forms)

ruby-on-rails,forms,checkbox,nested-attributes,strong-parameters

I haven't been able to test this code myself, but I have implemented similar code, so the ideas should be correct. The trick here is using each_with_index, and then passing that index to your fields_for call. This way the each additional milestone_id that you add via a checkbox will be...

accepts_nested_attributes_for hard code in Controller

ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,nested-attributes

The association you created along with the accepts_nested_attribute_for method will create a event_file_attachments_attributes on which you can add the corresponding event file attachment attributes, here is a quick example: In the controller: @event_file = EventFile.new(:event_member_ids => data['event_member_ids'], :user_id => current_user.id, :company_id => @current_company.id, :event_id => data['event_id'], :status => 0, :event_file_attachments_attributes...

Rails 4 Nested Attributes with fields_for Don't Save to Database

checkbox,ruby-on-rails-4,nested-attributes,strong-parameters,fields-for

Update venue_params method as below: def venue_params params.require(:venue).permit( :name,:address,:city,:state,:zip, parkings_attributes: [:id, :venue_id, :none, :street_free]) end Notice parkings_attributes(plural parkings) and not parking_attributes(singular parking). As you have 1-M relationship between Venue and Parking model you would receive parkings_attributes(plural parkings) in params hash BUT in your current code for venue_params you whitelisted parking_attributes(singular...

Rails4 Mongoid inheritance + Strong Paramters +Nested attributes

inheritance,ruby-on-rails-4,mongoid,nested-attributes,strong-parameters

as a workaround in the mongoid gem (version 4.0.0) in the file lib/mongoid/relations/builders/nested_attributes/many.rb I changed the creation of the object in the method process_attributes at line 109 to be klass = attrs[:_type].try(:constantize) || metadata.klass existing.push(Factory.build(klass, attrs)) unless destroyable?(attrs) instead of existing.push(Factory.build(metadata.klass, attrs)) unless destroyable?(attrs) and this solved my problem....

Return id from nested_attributes in javascript

javascript,ruby-on-rails,nested-attributes

@AlexAtNet thanks for taking the time to answer! What i did was to iterate with a for loop through the desired ids. I added also a hidden field in my form to count the prices so the ids I needed for the for loop. My js is: jQuery(function(){ $("item_item_prices_attributes_0_regular_price.bind("change", function(){...

Rails 4 nested_attributes update

ruby-on-rails,ruby,ruby-on-rails-4,nested-attributes

If you want to update an existing data record, you have to include the object ID on the attributes_param: user = User.find(1) user_data_id = user.data.id user.update(data_attributes: { id: user_data_id, race: '2' }) ...

Display user friendly Devise nested validation errors

ruby-on-rails,devise,rails-activerecord,nested-forms,nested-attributes

"custom-err-msg"Custom error Gem does not really depend on rails version. So it will best to use or otherwise you have override full_messages method by yourself or you have add nested model validation in parent model itself.

Django serve get-requests

django,get,nested-attributes

So your syntax for get_object_or_404 is wrong. You don't pass it an object: it gets the object for you. So: user = get_object_or_404(User, email=email) Now you've got a User instance, and you want to get the relevant profile, so you can just do: profile = user.userprofile Alternatively it might be...

Rails 4 nested form not creating the objects which it accepts_nested_attributes_for

ruby-on-rails-4,parameters,nested-forms,nested-attributes

subcategories_attributes are sent correctly within your params hash BUT content attribute is missing in them. "subcategories_attributes"=>{"1398706662184"=>{"name"=>"TS1", "_destroy"=>"false"}, "1398706664804"=>{"name"=>"TS2", "_destroy"=>"false"}} Notice there is no content key passed. So, all the subcategories records passed in subcategories_attributes are REJECTED due to the condition you specified in Category model: accepts_nested_attributes_for :subcategories, :reject_if => lambda...

How to create a simple nested signup form?

ruby-on-rails,ruby,ruby-on-rails-4,nested-forms,nested-attributes

You should learn the concept of form objects. You can easily implement this in Rails using ActiveModel. class SignupForm include ActiveModel::Model # define your signup form attributes attr_accessor :organization_name, :organization_note, :user_name, :user_fullname, :user_email def save organization = Organization.create( organization_name: organization_name, note: organization_note ) user = organisation.users.create(email: user_email, name: user_name, full_name:...

Model-independent Rails 4 file upload in dynamically loaded (nested) form field

ruby-on-rails,file-upload,nested-forms,nested-attributes,form-helpers

I assumed that the form had multipart set, because specifying multipart => true for a form_for helper is not necessary according to Rails documentation. The fix turned out to be pretty simple, however - it works after setting multipart: true in a html options hash for the form tag: =...

Nested object creates blank entry

ruby-on-rails,ruby-on-rails-4,nested-attributes

You don't use strong parameters in your create method so none of the parameters are passed over to your model. The model doesn't have any validation for the presence of attributes so it will just create you a blank record. In your controller, you need to change to use the...

fields_for not creating a record when making a new parent record

ruby-on-rails,forms,ruby-on-rails-4,nested-attributes,fields-for

I believe I see the issue. In your new_project action, try this: def new_project @title = params[:ti] @project = Project.new @project.participants.build end To elaborate: fields_for is not going to render anything if the association is blank/empty. You need to have at least one participant returned by @project.participants in order to...

Rails getting data from nested attributes

ruby-on-rails,join,nested-attributes

You can actually achieve this by setting up has_many through relationships between your models. There are great docs on this topic. class DataSet has_many :browse_options has_many :browse_option_datas, :through => :browse_options has_many :tradesmen, :through => :browse_option_datas end class BrowseOption belongs_to :data_set has_many :browse_option_datas end class BrowseOptionData belongs_to :browse_options belongs_to :tradesman end...

How do I update a nested resource without passing the data via a form

ruby-on-rails,devise,nested-forms,nested-attributes

I would overwrite the create action so that you can hardcode (and the user can't mess with) the role attributes. You're assigning them in the new action, but you'd need to have hidden fields so they get passed to create and persist into the database. However, that's not a good...

Rails - Validate Nested Attributes Uniqueness with scope parent of parent

ruby-on-rails,scope,nested-attributes,validates-uniqueness-of

A better option in terms of performances is described below. It is tested and works just fine. Why? Mapping emails can consume a lot of ressources when a lot of emails are at stake, so its better to perform the scope directly with the database. How? Cashing the account_id in...

rails 4 collection_select multiple nested attributes not saving properly

ruby-on-rails,ruby,ruby-on-rails-4,nested-attributes,collection-select

I prefer to do it more convenience way. # in your form <%= form_for(@post) do |f| %> ## your other fields <%= f.collection_select(:tag_ids, Tag.all, :id, :name, {include_hidden: false}, {multiple: true} ) %><br /> <% end %> #in your controller def post_params params.require(:post).permit([:title, :tag_ids => []]) end now instead of two...

Is it a good idea to use has_one nested attributes in rails?

ruby-on-rails,nested-attributes,has-one

I think you need to use polymorphic association as you need on model to belong to more than one model. You can use it like this: Edit: Changing the belongs_to :address to belongs_to :locatable as @vee corrected it. class Location < ActiveRecord::Base belongs_to :locatable, polymorphic: true end class Hotel <...

Rails 4: child record ID is saved but not its attributes, using nested form with has_many through relationship

ruby-on-rails,ruby-on-rails-4,nested-forms,nested-attributes,has-many-through

In your new action: def new @food = Food.new @food.subs.build end and in your view: <%= f.fields_for :subs do |sub| %> When you're passing directly an object, this object becomes the new form_builder's object - rails have no idea it is in any way connected with original object so it...

how to pass params to action#new (in a nested has_many association) via link_to

ruby-on-rails,forms,ruby-on-rails-4,nested-attributes,link-to

Add the following in your form: <%= f.hidden_field :session_id, :value => params[:session_id] %> So that the session_id persists till the create action....

Rails Forms with Nested Attributes from Join Model many_to_many

ruby-on-rails,many-to-many,nested-attributes

Update setup_new_project method as below: def setup_new_project(project) project.assigned_projects.build ## Updated this line project end Use project.assigned_projects(Notice plural) instead of project.assigned_project(Notice singular WRONG). User and AssignedProject model are in a 1-M relationship. So, you get dynamic method assigned_projects=(Notice plural), you are getting error as you called assigned_project=(Notice singular) which does not...

Rails 4 - Nested Object Won't Save

ruby-on-rails,ruby-on-rails-4,nested-attributes

If you send the parameter _destroy: 1 through your hidden field <%= f.hidden_field :destroy %> you instruct Rails to destroy the child moz object, or in your case, prevent it from being created. As for the second part of your question, if you inline the partial from this <%= f.fields_for...

Rails: Ordering in nested form

ruby-on-rails,ruby,ruby-on-rails-4,nested-attributes

This is how you specify the order: has_many :experiences, ->{ order(:experience_end_date) }, dependent: :destroy That will sort by ascending; for descending do this: has_many :experiences, ->{ order("experience_end_date DESC") }, dependent: :destroy You can usually find answers to such questions in the documentation, either in explanations or in the example code...

Rails with nested resources redirect Edit/Update method to Create method

ruby-on-rails,redirect,ruby-on-rails-4,nested-attributes

Are you defining routes twice because that can cause issue in rails. You should only define them only once. resources :models do resources :lineitems end Also run rake routes from the console and see what routes are forming. Actually when you are using this @model.lineitems.build you are re-assigning the lineitems...

rails has_many through create multiple join records with collection_select

ruby-on-rails,nested-attributes,has-many-through,collection-select

First you need to understand more about controller actions. You can read about them in the Rails Guides For example: def create @match = Match.create(match_params) @home_opponents = @match.home_opponents.create!(params[:match_opponents]) @away_opponents = @match.away_opponents.create!(params[:match_opponents]) if @match.save redirect_to @match, notice: 'Match was successfully created.' end end Match.create already saves the object, which you save...

Trouble in RSpec test - saving parent record twice

ruby-on-rails,ruby-on-rails-4,activerecord,rspec,nested-attributes

The issue is in sign_up_spec.rb. Your test has a let for user, which means the first time you mention user in your tests it will create a user. However, your application code is supposed to create the user itself. As I said in the comment, this is why in your...

can't be blank while using accepts_nested_attributes_for (Rails 4)

ruby-on-rails,ruby-on-rails-4,nested-attributes

The clue is in the error: Goals contact can't be blank In your Goal model, you have the following validation: validates_presence_of :title, :due_date, :contact_id Try removing contact_id to test if it will accept or not. If it does accept, it means you're not passing the contact_id through your params to...

Nested attributes in form not visible

ruby-on-rails,activeadmin,nested-attributes,formtastic

You forgot to pass your form builder to the fields_for block. <%= f.inputs "Track Exclusivity", class:'inputs align-left' do %> <%= f.input :exclusive %> <%= f.input :full_exclusivity, label: "Fully Exclusive" %> <%= f.fields_for :exclusivities do |ff| %> <%= ff.input :notes %> <%= ff.input :staff_notes %> <%= ff.input :industry %> <%= ff.input...

Multi nested attributes with ActiveAdmin

ruby-on-rails,activeadmin,nested-forms,nested-attributes

Turns out I was defining ":browse_option_data" wrong and I should have been calling for ":browse_option_datas" and also defined it this way in the Model for has_many.

Nested Comment body not being saved Ruby on Rails

ruby-on-rails,devise,nested-forms,nested-attributes

You don't really need to use nested attributes in this case at all. There is no reason to pass the user_id and app_id via the form either since they are known in the controller. Doing so just opens up the door for potential mischief. Like sending user_id: 1, body: 'My...

Form with nested models with many to many through relationship “can't assign mass attributes” error

forms,ruby-on-rails-3.2,nested,nested-forms,nested-attributes

Family and User are associated with 1-M relationship. In your view families/new.html.erb Change <%= f.fields_for @new_user do |ff| %> To <%= f.fields_for :users, @new_user do |ff| %> ...

NoMethodError in Index: How to Define the Nested Attributes?

ruby-on-rails,ruby,undefined,nested-attributes,cocoon

Answer to Your Specific Problem: In your index action you have: @quantified = Result.all.order("date_value") Calling .all before .order is the cause of your error. In Rails ActiveRecord, the .all command immediately triggers a fetch of items from the database. Since database IO fetching commands like .where and .order exist to...

Rails Nested attributes being duplicated

ruby-on-rails,ruby,nested-attributes

You don't need to iterate before fields_for since it renders your form for the number of existing associations. You can confirm this by changing the number of @taxable_pays to 3 and see how you get 9 (and not 6) items in your form. Change your controller to the following: def...

Rails 4 has_many association form not building

ruby-on-rails-4,associations,nested-attributes,has-many

Update fields_for in your form as below: <%= q.fields_for :answers do |a| %> <%= a.text_field :content %> <% end %> Note pluralized :answers and not :answer. As Entry model is associated to Answer in a 1-M Relationship, you should be using plural :answers in fields for. Right now as you...

Rails 4 nested attributes link_to_function

javascript,ruby-on-rails,ruby-on-rails-4,nested-attributes,link-to-function

That Railscast has several flaws - the most prominent being it only allows single form elements to be appended to the page (it preloads the JS link with a form element & keeps putting the same element onto the page -- problem being this element has the same id as...

Require nested params

ruby-on-rails,nested-attributes

I'll go out on a limb here and make assumption that you're working with a form submit and you don't want to add the record unless the name field is present. To give the name field a "required" characteristic it should be declared in the model itself, community.rb, for instance:...

Rails scoped uniqueness constraint throws error when updating nested attributes

ruby-on-rails,ruby,nested-attributes,unique-constraint,updating

This is happening because the widget updates do not happen all at once - they run one at a time. Rails checks uniqueness by querying the database for an existing row with the same data, and stops if it finds one with a different ID than the object you're trying...

Rails 4, retrieved many records with Model.where(related_model_id: 1), how to show each one in an individual view?

ruby-on-rails,rails-activerecord,nested-attributes

First of all: you've set up an association (has_many :questions), so you can just use @quiz.questions instead of a manual search (Question.where...). You just need to specify a sort order and then fetch a single record based on a minimum-value. Let's say you choose the id (created_at or any custom...

Rails nested Attributes of join table won't be saved

ruby-on-rails,nested-attributes

Problem is solved by removing the validations for project_id and user_id in the join table "AssignedProject" So the join Model looks like that: # Join Model AssignedProject class AssignedProject < ActiveRecord::Base belongs_to :user#, class_name: "User" belongs_to :project#, class_name: "Project" attr_accessible :project_id, :user_id, :position, :project, :project_attributes accepts_nested_attributes_for :project validates :position, presence:...

Rails has_many nested form No route matches [POST]

ruby-on-rails,forms,ruby-on-rails-3,nested-attributes

Update: w/o nested forms So I hear you only want to only edit the vehicle_report without touching the vehicle. Since you already have your vehicle_report as nested resource, you can modify your controller as follows: class VehicleRecordController < ApplicationController ... def new @vehicle = Vehicle.find params[:vehicle_id] @vehicle_record = @vehicle.vehicle_records.build end...

Rails 4 nested_attributes with has_one association rollback

ruby-on-rails,ruby-on-rails-4,nested-attributes

It is more likely to be an issue with validations than with strong parameters. In your case the user.email seems to be constrained to be unique, but it could be anything on the user or member models. Of course a forbidden parameter can also be a reason a validation fails...

Difference between 2 different nested hash in Ruby 1.8.7

ruby,hash,hashmap,nested-attributes,ruby-on-rails-2

You can use the form of Hash#merge that takes a block to produce the desired result in a compact manner: data1.merge(data2) { |_,ho,hn| ho.merge(hn) { |_,o,n| (o==n||o==''||n=='') ? nil : [o,n] } .delete_if { |_,v| v==nil } } .delete_if { |_,v| v.empty? } #=> {"3"=>{"passenger_type"=>["ADT", "ADTT"]}, # "1"=>{"passenger_type"=>["ADTT", "ADT"], "last"=>["JONES",...

Rails 4 - Access attributes of nested model in form

ruby-on-rails,ruby-on-rails-4,nested-attributes

Ok, got it!! The problem is the one-to-many relationship and the way I tried to access a single instance of user. The correct way to do it is: <% current_account.users.each_with_index do |user, index|%> <%= f.simple_fields_for :users, user do |user_form| %> <%= user_form.file_field :avatar, :error => false %> <% end %>...