39 questions
0
votes
0
answers
100
views
How to purge attached ActiveStorage files when updating a record in Rails 7?
I'm using Rails 7 with ActiveStorage to handle file uploads on a Post model. Everything works fine for attaching files, but I'm struggling with removing/deleting an attachment when the record is ...
0
votes
2
answers
1k
views
Why am I getting a CSRF token authenticity error when trying to submit a form_with through my stimulus controller?
I connected a form_with with my stimulus controller, then added the form itself as a target and added an action to point to my stimulus controller's submit function. When I then get the form and try ...
1
vote
1
answer
34
views
How to use form_with in Rails for multiple models that don't have controllers
I am trying to create recipe app that users can take. Part of the app is an admin users getting to create the recipes and instructions.
There is a User model/table with all the users. This has a
...
1
vote
1
answer
605
views
Rails 7: Forms having two buttons (One for GET request and One for POST request)
I am working on Ruby on Rails application and have designed a form.
I have two buttons in the form.
Generate Plot button which initiates a GET request
Save button which initiates a POST request.
The ...
0
votes
1
answer
965
views
Rails 7 : Multiple forms/buttons on one page, each one supposed to trigger same action but with different input, always triggers the first in list
Here's the issue I'm facing.
I'm creating miniature cards for my models, iterate on every item of the collection (using render @models) and each one has a button to trigger a form (POST) that goes to ...
0
votes
2
answers
64
views
NoMethodError | nested routes path problem in rails 6
I haven't been able to solve the error for a couple of days because of the nested path, what is the problem?
I realize that there is no such nested path as Rails is looking for, but why is he looking ...
0
votes
1
answer
1k
views
form_with and stimulus with hotwire doesn't work (Rails 7)
Select field with form_with, Stimulus and Hotwire, and Rails 7
I want to see a message in the console once I change the select value. I'm using Hotwire and Rails 7 but it doesn't work.
Code.
_form....
0
votes
1
answer
40
views
Together with the message, all information about all messages is displayed
I do chat on action cable. And I have a problem with post view. However, in order to show a message from a user, it additionally outputs the entire hash of all messages in this chat.
This what i get:
...
4
votes
2
answers
2k
views
Errors not displaying when rendering edit in Rails 7
My app is running Rails Rails 7.0.2.3
In my update controller action I have the line:
return render(:edit) unless @user_form.save
This renders the edit view on error .... but errors are not displayed....
1
vote
2
answers
628
views
How do I connect a general search form (form_with helper) to a specific route and pass the input to the params hash?
I'm having trouble connecting a form_with helper to a specific action. I want to search through my posts and so have created a search action in the posts_controller. The logic is working (tested by ...
10
votes
1
answer
4k
views
Rails 7: local (non-XHR) request with a form_with form
In Rails 7 a form generated with form_with tag sends remote request by default (turbo.js handles form submit event instead, whatever).
Previously one would pass remote: false or local: true parameters ...
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:...
0
votes
1
answer
191
views
Rails: "Validation failed: Class must exist" in a Form_with
I've a multiple relation table named Order which belongs_to a Relai(to avoid singular/plurials complications), a Customer and a Composition. I set my Order model accordingly with nested_attributes as ...
0
votes
1
answer
950
views
Rails ujs and remote form, How to stop form submission the programmatically submit form
I am using rails form_with as a remote form. Before submission I want to display a custom confirm box with a dynamic message. After the box is indeed confirmed I want to eventually submit the form.
I ...
0
votes
0
answers
55
views
Reails remote form format exists but not recognized
The following form intends to generate an XHR response
<% articlediscounts_for_article = @articlediscounts.where(article_id: article.id).first %>
<%= form_with(scope: ...
0
votes
1
answer
638
views
Rails 6.1 form_with doesn't send PUT request
I added the method: patch to the form_with helper (like it said to in this SO post)
<%= form_with(model: [:admin, contest], method: :patch) do |form| %>
...
and the <input type="...
0
votes
1
answer
214
views
form_with producing wrong controller (only on some routes)?
This is in application.html.erb, and it works on 95% of the pages in my app:
<% ['usd', 'eur', 'aud'].each do |currency| %>
<%= form_with url: {controller: :home, action: :currency_select},...
0
votes
1
answer
136
views
Showing alerts using form section value
How can I use the selected value in form for alerts?
Is there a way to get it by getElementById or equivalent?
Form
= f.select :some_key, some_array
`= f.submit 'Submit', data: { confirm: t('views....
0
votes
2
answers
828
views
Rails - My 'create/new' method doesn't work
I've created a form so the user can add a new picture to the website catalog, but for some reasons it doesn't work. Once the form is filled out, I click on the 'Submit' button but nothing happens, I ...
2
votes
1
answer
9k
views
Rails form_with select selected option
I have a form without a model backing it built using form_with in Rails 6:
<%= f.text_field :one %>
<%= f.select :two, [['Option 1',1],['Option 2',2]] %>
<%= f.submit 'Submit' %>
...
0
votes
1
answer
583
views
How to add an "any" option for a select menu using form_with
I am trying to add an "any" section to my game filters. In a wide view it works fine I just reload the page passing the link the other needed params like this:
<%= link_to games_path ...
4
votes
2
answers
6k
views
Change 'Please match the format requested.' to something else?
Is there an easy way to customise the message that appears when the pattern: "([A-Za-z0-9\-\_]+)" argument is not satisfied and this message appears:
e.g.
<%= f.text_field :username, ...
0
votes
0
answers
178
views
Prevent form_with from generating a parameter and submitting it (all by itself)?
When a form_with submits, it submits all the desired parameters, but also a parameter called "booking", and I have absolutely no idea where this parameter came from. It's not contained in ...
1
vote
1
answer
567
views
How to change the message when a form input doesn't match the pattern parameter?
A pattern argument can be provided to a form field as described here
Example (regex from here)
<%= f.text_field :username, pattern: "([A-Za-z0-9\-\_]+)" %>
When the regex is not ...
4
votes
2
answers
4k
views
How to add a hidden field to form_with?
I am attempting to add a hidden field to a form_with.
Here are 3 attempts (and results / error messages)
First attempt
From: https://guides.rubyonrails.org/form_helpers.html
<%= hidden_field_tag(:...
1
vote
1
answer
2k
views
Custom route param and form_with not using the param
I'm trying to allocate an address a custom id so it's not easy to guess the record (for people who want to add and change other people's addresses). For some reason, whilst I can create a record with ...
1
vote
1
answer
5k
views
Can't make Stimulus JS data-action in collection_select Rails 6
I'm new to Stimulus JS. I'm a little stuck trying to make a simple event fire using collection_select in a form (created with rails g scaffold).
Here's my dropdown-controller.js (stimulus) file:
...
0
votes
1
answer
440
views
country_select gem throws "NoMethodError", undefined method `country_select' for #
I am new to rails but I think I'm following every step for using this gem.
However, I'm getting a NoMethodError.
My steps:
I ran gem install country_select -v 3.1.1 in terminal.
I stopped my server, ...
1
vote
2
answers
147
views
Ruby on rails, can't update database via web interface
I'm programming a Book library system with a SQL Lite database in the background. Via the console I can add and update books without a problem. And I have already made a view where I can add new books ...
0
votes
1
answer
305
views
Ruby on Rails form error not giving any output/ not working
Hello guys I searched everywhere on how to output form errors but no luck. I tried almost all the code I found on the internet but still didn't work.
Here are some of my files:
view/books/new.html.erb
...
1
vote
1
answer
813
views
How to use Rails 5.2 form_with to trigger a specific action?
My application needs to duplicate a Skill (from skills index) as many times the user needs it in his cart. So I decided to trigger the add-to-cart method of the skills_controller when the related form,...
1
vote
1
answer
551
views
Nested routes - rails 5.2.4 - Undefined local variable or method
To register addresses for clients in my application I am using nested routes, however when clicking on the link to register a new address or to edit an existing address the system presents the error:
...
0
votes
1
answer
644
views
Return an array using `form_with`?
In my view, I have several checkboxes, and I want to send back an array of which are checked. I have achieved this by writing the HTML myself, but I'm wondering if there's a way to do it using ...
0
votes
0
answers
168
views
Rails 6 Params not nested under model, sent from different controller. form_with
I see ActionController::ParameterMissing (param is missing or the value is empty: order)
Its clear order is missing from my params Hash.
My parameters dictionary is flat and does not include {order=&...
1
vote
1
answer
73
views
from_with tag causing internal server error in Rails
I'm new to Ruby on Rails and am following the online tutorial here: https://guides.rubyonrails.org/getting_started.html
As soon as I try to implement a 'form_with' element I get the following error ...
0
votes
1
answer
124
views
uninitialized constant Authlogic::Session::Validation
I'm upgrading a rails 4.2 site to 6.0 and am receiving
uninitialized constant Authlogic::Session::Validation
when I try to load a form, presumably because the Validation module was removed from ...
0
votes
1
answer
1k
views
Rails permitted parameter not showing up in console
I have a pair of models, Preset and Plot
class Preset < ApplicationRecord
belongs_to :user
has_many :plots, :dependent => :destroy
accepts_nested_attributes_for :plots, ...
0
votes
2
answers
454
views
Rails _destroy field appearing twice in form
I have two models, Preset and Plot, as below:
class Preset < ApplicationRecord
belongs_to :user
has_many :plots, :dependent => :destroy
accepts_nested_attributes_for :plots, ...
3
votes
1
answer
2k
views
Rails form_with hidden_field value encrypted for new object
I have a simple form for creating a new model. The model has an attribute panel that is set in the Controller. I think it should not matter, but panel is an enum.
def new
@order = Order.new(panel: ...