Questions tagged [ruby-on-rails]

Ruby on Rails is an open source full-stack web application framework written in Ruby. It follows the popular MVC framework model and is known for its "convention over configuration" approach to application development.

0
votes
0answers
7 views

Routing post requests with a polymorphic comment table

I have a user and goal table that associate with a polymorphic comment table. My question is what's the best way to setup my comments controller to differentiate between the two? I'm looking more for ...
0
votes
3answers
13 views

Trying to select all objects where at least one associated object doesn't match the query

I have two associated models. A Product has many DescriptorFiles, and a DescriptorFile has a boolean attribute approved. I want to find all products where none of the associated descriptor_files are ...
0
votes
0answers
19 views

How to create custom update action before destroy object

I want to add update some field on my record before soft delete it. But I don't understand what I do wrong. Help me please to understand me wrong. controller.rb def set_the_reason @advert = ...
0
votes
1answer
16 views

Cannot eagerly load the polymorphic association :item

I need get all the accounts of the @client (has_many :accounts, as: :item is the relationship). Have a Account model with :item polymorphic field (belongs_to :item, polymorphic: true, nothing more), ...
0
votes
1answer
10 views

Pagination removes AR scopes in controller

Currently using api-pagination gem with kaminari. I also have a simple scope to limit the amount of objects returned. For whatever reason though, the pagination removes the return array of the scope ...
0
votes
0answers
14 views

Running gem tests

I am breaking a monolithic Rails app into several gems. They all have a load of features that depend on the main application. The purpose is to have a way to install the main application without all ...
0
votes
0answers
7 views

Recaptcha crashes digital ocean server (504 error)

getting 504s on DO when trying to add recaptcha via rails + devise I've added recaptcha on a digital ocean server. I followed the general instructions here -> https://github.com/plataformatec/devise/...
0
votes
2answers
13 views

How to do an RSpec oneliner to test a :count change

we all love oneliners, they are so cool but they are also so undocumented how can I do an oneliner of this code (that currently works brilliantly)? it "deletes the user" do expect { destroy_user }....
1
vote
2answers
22 views

passing a variable to an ActiveRecord query

Let's say I have a query: Foo.where("lower(bar) LIKE ?", "%#{baz}%") which transforms to plain SQL as: ... WHERE (lower(bar) LIKE ... and works perfectly. But instead of bar I want to pass an ...
0
votes
1answer
18 views

Association between 2 tables doesn't work

I'm new to RoR and I want to create simple page like a task manager (to add and remove tasks) so I created 2 tables with association between them (Track and Item). Here is 2 models: class Item < ...
0
votes
0answers
32 views

undefined method `text' for #<Enrollment:0x0000000005d124a0> [on hold]

I am facing this error: "undefined method `text' for #" when i am creating a new enrollment(table name enrollments). when i click on 'Add a new Enrollment' the error above appears. More infos in the ...
0
votes
0answers
10 views

What is ActiveStorage's 'attach' doing behind the scenes when files are uploaded to a service as like AWS?

I can't seem to find a detailed explanation of what process the attach method initialises when uploading a file (not direct upload) to a configured service such as Amazon S3. Does the file get ...
0
votes
3answers
17 views

Rails 5 left_outer_join with specific saved ID

I have a system with the following models class Application < ApplicationRecord has_many :offers, dependent: :destroy belongs_to :accepted_offer, class_name: 'Offer', ...
0
votes
1answer
22 views

Unable to resize image using image_tag (rails activestorage)

i'm using activestorage rails 5 in my project for uploading images when image uploads it did not resize to my given size in image tag. it only working with square images. help me i want to store ...
1
vote
1answer
22 views

How to encode RSA-OAEP with SHA256 hashing in Ruby or ROR

I am encoding a JSON data in Ruby by using RSA-OAEP with SHA256 hashing algorithm but I am not sure how to achieve in Ruby. I found a gem chilkat I have tried to encode the JSON data using Chilkat ...
0
votes
1answer
23 views

using an instance of appointment in the appointment model

I've created a form with some radio buttons and had to interpolate the appointment.id into the radio button and the label. However, Rails is throwing the error: undefined method cancel_3 for ...
0
votes
1answer
32 views

Dry-Validation - no implicit conversion of Float into String on rules

I'm trying to validate the value of a key into my schema. But I'm getting a no implicit conversion of Float into String because the value is a float and I'm using a regex to validate the format. ...
0
votes
2answers
47 views

How to interpolate in a ruby method name

Is it possible to interpolate in a method name? I'm trying to make this work def "cancel_#{appointment.id}" but having no luck. thanks
0
votes
0answers
17 views

how to have i18n working with shared partial caching

All my app have been transform to work with i18n but, the last thing i need is to cache the partails for each language. I've already seen some method to cache like this : <% cache([I18n.locale, ...
1
vote
1answer
21 views

Should I set explicit versions in a Gemfile?

I'm used to defining gemfiles with simple commands, like gem 'devise'. I'm now putting my App in production through a dockerized container on AWS, together with a pipeline that pulls and builds new ...
2
votes
1answer
32 views

Is there a Rubocop configuration specifically for rails 5.2.3?

I have just created a fresh Rails application using Ruby 2.6.3 and Rails 5.2.3 and the only thing I have done is installed Rubocop. After installing Rubocop v0.70.0, and running bundle exec rubocop ...
-1
votes
2answers
21 views

How can i get User name in a table where user_id is used as foreign key

I am using Devise gem for user Authentication. User id is as foreign key in article table How can i get writer name through User_id in a view Show_article.html.erb I can access user_id in ...
-1
votes
2answers
28 views

Rails migration to add a column of type array of objects

I would like to add a column of type Array of Objects. "users_to_employer":[ { key1 : value, key2 : value, }, { key1: value, key2: value, } ] I am ...
0
votes
0answers
22 views

Unable to access rails localhost running on AWS Ubuntu from my Windows desktop

I am running Rails server on an AWS Ubuntu instance. And I am trying to access the server from a browser on my Windows desktop. This used to work perfectly fine until yesterday. I started to get a ...
-1
votes
0answers
35 views

How to store zeros in db in rails

I have model with filed length - decimal , scale: 8, precision: 4. If I enter 5 in the field, there is 5 in the database. If I enter 4.4 in the database there is 4.4. But if I enter 4.500 in the ...
0
votes
1answer
21 views

Error on Rails app: Cannot stat '/path/to/app/current/passenger_wsgi.py': Permission denied (errno=13)

I've encountered something very strange. I've had a Rails app running on a nginx server on Centos 7 for over a year now, and it always worked. I checked back after a few months and I got this 500 ...
0
votes
0answers
15 views

uninitialized constant MetaTags when gem added in rails engine and loaded in another application

I am currently building a rails engine and in my gemspec file i have this gem meta-tags which i have added like this insurance.gemspec $:.push File.expand_path("../lib", __FILE__) # Maintain your ...
0
votes
1answer
17 views

Why doesn't FactoryBot save passwords in the test database?

I have just run into a situation where I had to tack down why my test user could not login in a system test. It turns out that the password word for the user was nil. I ran binding.pry after a user ...
0
votes
2answers
18 views

AbstractController::DoubleRenderError (Render and/or redirect were called multiple times in this action

Im create a messages system where one user send message and the other user receive the message with realtime update. It was working before but now im getting in error and nothing render or get ...
0
votes
1answer
30 views

Rails - activerecord model serializer group results by specific column in the foreign table

I want to use the ActiveRecord model serializer to show results from the primary key table and foreign key table. However, I want the results to be presented grouped by a column in the foreign key ...
0
votes
1answer
38 views

Apply deep_symbolize_keys! to array of hashes

deep_symbolize_keys! converts string keys to symbol keys. This works for hashes and all sub-hashes. However, I have a data like this: arr = [ {'name': 'pratha', 'email': '[email protected]', 'sub': { 'id': ...
0
votes
1answer
26 views

Is the :through association the correct way to link a joint table in Ruby on Rails

I have 3 tables named Users table, Messages Table and the Message_users Table and the Users table will be be used to store users' info while the Messages table will ...
0
votes
1answer
20 views

How to pass element id to cable subscription?

I have ActionCable set up and working with a general Message channel. However, I need to limit the channel subscriptions to a single Message. How should I pass a message_id to the subscription? I ...
0
votes
0answers
13 views

Starting rails server on VSCode [duplicate]

I'm trying out Microsoft's vscode and enjoying it up until now.. I can't get the rails server started. I'm just doing rails s and this is what I get: => Booting Puma => Rails 5.1.4 application ...
0
votes
0answers
20 views

Purging a active storage attachment will not delete attachment record

I have a model "Attachment" configures as: Model class Attachment< ActiveRecord::Base has_many_attached :files end COntroller def remove @attachment = Attachment.find_by_id(...
0
votes
0answers
8 views

Previewing Video attachement Rails Admin, Active Storage

I am using ActiveStorage 5.2.3. I have one_attachment and multiple attachments relations in the same model. class Post < ApplicationRecord has_one_attached :image has_many_attached :photos ...
0
votes
0answers
16 views

rake aborted Command failed with status (1): [docker-compose run --rm peatio bash -c "./…]

I am new to the docker and when I run the command rake service:all, I don't know why I found the error in installation peatio. This for the Ubuntu. ----- Running hooks ----- docker-compose run --rm ...
2
votes
1answer
38 views

My Rails Aplication start to raise ActiveRecord::ImmutableRelation in some random queries

since yesterday, my production app starts to raise ActiveRecord::ImmutableRelation in some queries of my entire application! I can't imagine how to gives an exact context of every error since this ...
0
votes
0answers
12 views

Add custom rows when generating CSV from datatable using jquery's table2csv

On my HTML front end I have a dataTable. It's showing up properly. I want to generate a CSV for the data in the table. I was able to do so using $('#ticket-classification-csv').on('click', ...
0
votes
1answer
23 views

You must use Bundler 2 or greater with this lockfile (issue not addressed in other posts)

When I run rake db:migrate from local machine, I get You must use Bundler 2 or greater with this lockfile. I can use when is listed here and use bundle exec rake db:migrate, and it works, but, I ...
0
votes
1answer
14 views

Does Rails with Action Cable run with NGiNX proxying in front of Puma?

I am aware that there are 1-2 other questions about this theme - but none of them seems to cover my angle or offer a solution; My browser console says: WebSocket connection to 'wss://sucker.alco.dk/...
0
votes
2answers
31 views

Ruby on Rails: link_to vs button_to

I am having trouble implementing the method link_to. My program uses a link to call a controller method which performs some logic and renders a partial. The issue is I cant get the link to call the ...
1
vote
0answers
29 views

Unreachable rails application in simple docker container

I have a simple docker image with a bare-bones rails app defined in it. When I run... $ docker build myimage . $ docker run -p 3000:3000 myimage ...and then run... curl http://localhost:3000 ......
0
votes
1answer
21 views

Rails ActiveStorage issue: “file not found” error for rails_blob_path, even though the path works manually

I have a small Rails app that works fine locally, uploading a docx file using ActiveStorage and converting it to html (among other things). To deploy this to Heroku, I need to change from using the ...
0
votes
1answer
17 views

Advice on integrating a previously created database that contains encrypted fields into a Rails app

I am looking for some advice on how I could go about integrating an encrypted, pre-existing database into a Rails app . I already have experience on how I can access the table data when the data is ...
0
votes
0answers
17 views

Ahoy gem created mutually exclusive migration?

I tried to learn new stuff and use Ahoy gem for my private project. While doing research online, I encountered one repo with Rails 4.2 and Ahoy 1.6 and one thing struck me. Then I started googling and ...
4
votes
1answer
51 views

Ruby on Rails - Why do nested transactions that “raise ActiveRecord::Rollback” don't roll back?

I would expect a and b to be nil since the raise in the inner transaction will “bubble up” to the outer transaction, but thats not the case. a and b still have values. Why is this happening? a = nil ...
0
votes
0answers
17 views

After using establish_connection to switch databases in Rails, how can I switch back to the standard database?

I've currently got a task I'm using to import some modified data from a secondary database. I can connect and pull the data without a problem. secondary_db = ActiveRecord::Base.establish_connection(...
-1
votes
4answers
50 views

How to get even groups in ruby?

Let's say I want to get a certain number of even groups based on a collection of records with varying count. How is this possible? I'm looking for a method like objects.in_x_even_groups(4) Update: ...
0
votes
1answer
21 views

rails model call back before_validation

I am using rails 5.2.3 If I inherits Active Record I can definitely use before_validation callback. But I only use include ActiveModel::Model like this # MortgageAmount model class MortgageAmount ...