148 questions
0
votes
2
answers
837
views
Rails 7.0.4- form_for - collection_select with multiple options in edit action
I have three tables:
Staff
Staff_locations
Locations
Business case: Staff can work in multiple locations. Association between Staff and Location is done through staff_locations table. While creating ...
1
vote
2
answers
320
views
Postgresql JSONB nested form ruby on rails
I have product as active record table and option_type as activemodel model. option types is an array of objects as follows,
[
{name: 'color', values: ['red', 'blue']},
{name: 'size', values: ['...
0
votes
1
answer
159
views
Rails 6 nested not displaying form_with
class CustomerType < ApplicationRecord
belongs_to :workspace, inverse_of: :customer_type
validates_presence_of :workspace
end
class Workspace < ApplicationRecord
validates :name, presence:...
2
votes
1
answer
374
views
form_for with :slug instead of :id
<%= form_for [current_user, @task] do |f| %>
gives users/:id/tasks but I would need users/:slug/tasks as I am using:
resources :users, param: :slug do
resources :tasks, only: [:index, :new, :...
0
votes
2
answers
701
views
How to create a Child before associating it to its Parent in rails?
I have Categories (Parents) within which are listed Products (Children).
I want to be able to create a new Product directly from the navbar, anywhere in the app and then, during the creation, assign ...
1
vote
1
answer
461
views
form_for collection_select not showing saved selections on edit
I have a form that I'm using for both new and edit. The form has fill-ins for product name, description, etc.
Also, the user can either select an item from the nested drop down (collection_select), ...
0
votes
1
answer
308
views
Rails form rendering multiple times if using `.build`
So I have a user form form_for that accepts nested attributes from account_prices. Whats happening is on my user controller I have this private method.
def pre_build_user_account_prices
if @...
0
votes
2
answers
67
views
Unmatched Constraint error with Form_for with Triple Nesting
I am making an events app where each event can have multiple to do lists each with their own tasks.
I am struggling with the third level nesting of the tasks (todo_items)
Here are my models:
Event....
2
votes
2
answers
3k
views
Rails form with nested attributes. text_field not appearing
Issue: I have a nested fields_for text_field not appearing, I am not sure what I have been done wrong.
Goal: While creating a record, iterate through a model with preset variables, and save a file (...
0
votes
2
answers
291
views
rails wrong number of arguments (given 9, expected 0) with form model
I'm using this to build a form model (i want to create a Transaction and an Address, and the address must belong to the transaction). I'm getting a rails wrong number of arguments (given 9, expected 0)...
0
votes
1
answer
113
views
Rails Nested Form - Creating a new Meeting from Club
I have a User, Meeting, and Club Model.
A User has_many :user_clubs, has_many :clubs, :through => :user_clubs.
A Club has_many :user_clubs, has_many :users, :through => :user_clubs, and has_many :...
0
votes
1
answer
173
views
How to filter records to be edited by nested_form_fields gem in Rails 5.2?
I use the nested_form_fields gem to tranlsate some specific fields in a technical document. Translations are nested fields associated to the document, so that each document has one instance of ...
3
votes
1
answer
2k
views
How to use enum with checkbox rails
I want to create a question list, to decide that question has multiple correct answer or not, I use a checkbox field:
<div>
<%= ff.label :multi_correct, t(".multi"), class: "field-label" %&...
0
votes
0
answers
167
views
Create a new object instead of updating the current one using SimpleForm simple_fields_for
I have the following nested form in my product_models/new.html.erb
<%= f.simple_fields_for :product_category do |g| %>
<%= g.input :name, placeholder: "Category name", label: "Category", ...
2
votes
1
answer
341
views
Why does strong params order in Rails matter?
In my product_model_controller.rb I have the following code for the strong params:
def product_model_params
params.require(:product_model)
.permit(:name, :product_category_id,
...
0
votes
2
answers
665
views
Rails: remove the label from a simple_form_for collection association
I am trying to remove the label that is auto included when we use '.association' of the simple_form_for. But, regardless of what I do, the title and its <hr> continue to be displayed.
I tried:
...
0
votes
2
answers
507
views
Rails model validation on form with new parent and child
I'm new to rails- but now wondering, are Rails validations lost on model objects when in my form I'm trying to create both the child and parent at the same time?
In my example (models in bold)
1 - ...
0
votes
2
answers
207
views
Creating nested form with devise
I would like on the form page for a campaign for a user to be able to create cities as well. I followed http://railscasts.com/episodes/196-nested-model-form-part-1?view=comments and https://medium.com/...
0
votes
0
answers
66
views
integrating a homemade captcha to sign up and sign in?
So I have a basic sign up, sign in site with username and password. I don't want to use recaptcha and was wondering whether i can create my own?
So have for example 'what colour is an orange'.
I ...
0
votes
1
answer
28
views
Rails : user_addresses vs @shipping_address of a User in form_for
I've got a User who's got multiple UserAddress
When I use :
<%= f.fields_for :user_addresses do |f| %>
My hash is nice :
"user_addresses_attributes"=>
{"0"=>{"default"=>"0", "...
0
votes
1
answer
87
views
Nested form don't save
I'm new do rails and MVC. I'm trying to save to my database a nested form that I made using simple-form and nested-form-for gems.
When I submit the form only the 'parent' model is created and saved.
...
1
vote
2
answers
1k
views
Create record using through association and nested_form_for rails
The following is my model structure
role.rb
has_many :user_roles
has_many :users, through: :user_roles
has_many :companies, through: :user_roles
user.rb
has_one :user_role, dependent: :destroy
...
2
votes
0
answers
579
views
Rails gem 'nested_form_fields' doesn't work in the right way
I'm using 'nested_form_fields' gem to build Rails form. It does work but not in the right way.
When I click the delete button, the fields are all deleted at once.
(When I add three text_fields, and ...
0
votes
1
answer
230
views
Create 3rd level child in a single form - Rails 5
I'm building a simple top-to-bottom Workout Routine app on ROR. I'm able to create a Workout Day (parent) and an Exercise (child) on the same form. But I can't seem to save the Weighted Set (...
0
votes
1
answer
105
views
Rails form_for, creating event with categorization
I'm kinda new to ruby on rails, I've been reading documentation on assosiations and I've been having an easy time (and usually a quick google search solves most of my doubts) however recently I'm ...
0
votes
1
answer
1k
views
Onchange event inside nested_form in rails 5
I am using nested_form in my rails application. I need to add onclick event which adds first two fields and render the sum in third field. This script should run in all the nested fields. I tried the ...
2
votes
1
answer
735
views
rails strong parameters not work correctly
i have a rails app. i have strange problem in saving form
this is my ticket model .
class Ticket < ApplicationRecord
belongs_to :user
has_many :ticketissues , inverse_of: :ticket
...
0
votes
0
answers
581
views
Active Admin has many form use same model twice in tabs
I have this PostApplication Model and PostApplication has_many Documents in this below activeadmin resource which contains has_many form.
I want to show various records of Document model based on the ...
0
votes
1
answer
83
views
rails deeply nested form_for not able to save twice
I have a form where teams can register for a tournament. The form saves & routes as expected when I first save the form, however if I return to the root_path & repeat the process of ...
4
votes
4
answers
2k
views
Rails 5 - save rolls back because nested models parent model is not being saved before child model
Ok folks, Rails 5 has really had its nuances differing from Rails 4. What I have going on is that every time I click the submit button on the form it reloads with the error Profile user must exist and ...
0
votes
1
answer
56
views
One to Many Nested Models form not saving
Ok so I had this issue with one to one relationships and I am going to figure that it is a similar issue with pluralization. I have tried to put in @payment.profile_notes.build and it still does not ...
0
votes
2
answers
381
views
Rails 5 trouble with saving a nested fields_for .. error message <xxx> must exist
I have the following models:
class Person < ApplicationRecord
has_many :interests, dependent: :destroy
accepts_nested_attributes_for :interests
validates_presence_of :email
...
0
votes
2
answers
590
views
Rails model with nested attributes fails to save but no error message is displayed
I have the following Rails models that communicate through a many-to-many relationship:
class Task < ApplicationRecord
belongs_to :case
has_many :task_actor_roles
has_many :task_artifacts
...
0
votes
1
answer
421
views
Empty associations for fields_for if the content is added dynamically via jquery
I built a form_for with 4 associated models. I created nested fields_for which can be added dynamically with the code below. My form works if I call the 'edit' method but if I use the method below to ...
0
votes
1
answer
152
views
Rails: Nested form_for Errors: 'ActionController::UrlGenerationError'
I am having trouble using the form_for correctly for my nested resources.
I have the following set up in my models:
team.rb
class Team < ApplicationRecord
has_many :superheroes
...
0
votes
1
answer
641
views
Nested form_for in rails
I have Test model and User model. Test model is having many users. Test controller is as below.
class TestController
def create
Test.create(testparams)
end
private
def testparams
...
0
votes
2
answers
852
views
Rails nested_form inside nested_form
I have the following models and relations:
Rate fields
t.string :type
t.string :name
class Rate < ActiveRecord::Base
has_many :category_rate_requests
end
CategoryRateRequests fields
t....
1
vote
0
answers
2k
views
Rails form_for many to many relationship
Please forgive me if this is a simple question. I've spent some time searching SO and have not fund a clear answer for this question. I'm also new to rails.
I have a regular old many to many ...
1
vote
0
answers
90
views
Rails 3.2 fields_for not showing on has_one and accepts_nested_attributes_for
I use gem 'nested_form' in rails 3.2
Models:
meeting_agenda.rb:
class MeetingAgenda < ActiveRecord::Base
has_many :meeting_questions, :inverse_of => :meeting_agenda
...
1
vote
1
answer
1k
views
Multiple image uploads in Rails from the same form_for?
I am having some trouble figuring out how to upload multiple images using a single form in a view. Basically, I have a form for articles on a blog that consists of a title text_field, a body text_area ...
3
votes
1
answer
645
views
nested form to update has-many parent AND create a *single* child object
I want a form to edit a single new child object and the parent object in one go (in a has many relationship). If I create a new child in the controller with @child = @parent.children.new, the ...
0
votes
1
answer
4k
views
Rails - Use fields_for to create multiple nested objects
Hoping someone can help out with this. I have two models order and date_order. Each order can have multiple date_orders, and I should be able to create many date_orders as I create an order.
How do I ...
0
votes
1
answer
83
views
Rails - Nested Forms will create, but information won't be saved
I've been struggling to get my nested form to save the users' inputs. The "outer" form saves the information perfectly. The "inner", or nested, one creates a new object, and passes hidden-field ...
0
votes
2
answers
241
views
Rails model with 2 foreign keys but only one gets saved when submitting form_for
I'm trying to save a form_for with nested resources that inputs data into a model that belongs to 2 other models and has 2 foreign keys: User_id and listing_id.
The problem is that only the user_id ...
0
votes
1
answer
275
views
Undefined Method in Form_For Helper
I have a post model that belongs_to a category model. The post resources are nested under the category resources. I'm building out a form_for @post to create a new post. However, I'm getting the ...
1
vote
1
answer
926
views
Rails fields_for and not creating relationship with nested object
The model "Formula" has many "Operands" created using a simple_nested_form, using fields for. It seems the process is correct, and no errors launched, but operands are not saved.
Formula model:
...
0
votes
1
answer
543
views
"Invalid association": nested_form_for with has_many through
I am trying to dynamically add an arbitrary number of ingredients to a shoppping list using the nested_form gem. This is a has_many through relationship, and I'm having trouble finding exactly what I ...
1
vote
1
answer
1k
views
Rails 4+ Edit multiple objects in one form BEST PRACTICE
I have a User, Drinks, Gyms, Foods Model.
class User < ActiveRecord::Base
has_many :drinks
has_many :foods
has_many :gyms
end
I track the number of drinks a user had during the day and save it ...
1
vote
1
answer
411
views
Using devise with nested form on sign_up
The form doesn't show the Pessoa's field, what's wrong?
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<...
1
vote
1
answer
1k
views
Updating a Many-to-many relationship with additional field by form_for
Is there a way to update a field relative to a many-to-many associations via form_for?
Theses are my models:
class Grad < ActiveRecord::Base
belongs_to :school
has_many :grad_courses
...