Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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
9 views

Set default for a prop that has different types in VueJS

New to Vue.js. I want a prop that can accept either a string, number, or Boolean. And I want the default to be null. Not sure if this is the best approach but I'm using this prop for a form that has ...
0
votes
0answers
16 views

Rails 5 send images png from my API rails controller

I have an api it has a model Images with two attributes: url, name. the images are in folder assets/images (just 20 images png), the db table saves the url of the image file, and a custom name, when a ...
0
votes
0answers
7 views

Having trouble testing Rails Model validations with shoulda-matchers and factory-girl-rails?

Model: validates :email, uniqueness: { message: "has been taken." }, presence: { message: "cannot be blank." }, length: { minimum: 3, message: "is too short, must be a minimum of 3 characters....
0
votes
0answers
13 views

rake assets:precompile with commas

Can you run rake assets:precompile and use commas in place of semi colons? I ask because i'm running into another issue where my production js asset statements are separated with commas but my staging ...
0
votes
1answer
18 views

ROR Association | undefined method `map' for nil:NilClass

When i want to post my Post i have this: See the problem I use Rails on Archlinux. This is my Controller posts_controller.rb: module Admin class PostsController < ApplicationController ...
1
vote
2answers
32 views

Check whether array is sortable

Is there a way to avoid this error when sorting an array? ArgumentError: comparison of Hash with Hash failed I'm looking for something like this: a.sort if a.is_sortable?
0
votes
1answer
19 views

Ruby on Rails - Edit Update Action

I have a form that I wanna edit some informations, so I drew a get route for our edit form and a update route. Routes.rb: resource :guide_dog_forms get '/cao-guia/:id/editar', to: 'guide_dog_forms#...
0
votes
0answers
15 views

Caching an entire response body in rails

I want to cache an entire JSON response in rails. The JSON is serialized with ActiveModel. I don't want to serialize it each time. This is a big complex list that doesn't change often. Right now I ...
-1
votes
0answers
13 views

Rails console slow tab completion?

Running arch, when developing rails the console's tab completion for everything is incredibly slow. Even if the list it returns is inherently small. User.n for instance shouldn't return a horrid ...
0
votes
0answers
9 views

How to enforce eager loading of associations when importing records using Searchkick with Rails4?

For this setup with default (unspecified) search_data: class Item < ActiveRecord::Base searchkick has_many :quantities, dependent: :destroy scope :search_import, -> { includes(:quantities) } ...
0
votes
2answers
19 views

Routing Error , No route matches [GET] “/categorys/new”

The name of the table is "category", controller is "categories". I have added resources :categories in routes file. Why is it showing "Routing Error No route matches [GET] /categorys/new"? following ...
0
votes
1answer
12 views

recaptcha gem No site key specified

I got this error no site key specified In my gem file gem 'dotenv-rails', :require => 'dotenv/rails-now' gem "recaptcha", require: "recaptcha/rails" In my controller def index @contact=...
0
votes
0answers
21 views

Select2 JS lib not working on Rails app

I was given this Rails app that utilizes the select2 JS library and can't figure out why it's not styling my select list. It's working in production. I created a staging server from a snapshot of the ...
0
votes
0answers
15 views

How to clear localStorage after logout user with rails?

I have ROR application and i added countdown timer to it . The timer count from 15 to zero then disappear. What i'm doing is to prevent count again on refresh page , so , i stored start value in ...
-3
votes
0answers
23 views

How can I make my polymorphic model work?

I've got two models User and Good and Image as polymorphic association. I made Image polymorphic: true and use carrierwave gem for creating uploader mount_uploader :image, ImageUploader in Image model ...
0
votes
0answers
8 views

Roo Gems : Exporting files work in development, not in production

as I said, I'm using Roo Gems to export xlxs file on my app. I have a xlxs file, with 30 000 records inside. When I've deployed my app, I have an application error : undefined method 'model_name' ...
1
vote
1answer
23 views

Rails 5.2: how do I revert the Postgres specific interpretation of an array in 'where' as a parameterized IN clause?

After upgrading from Rails 5.1 to Rails 5.2, only for Postgres (using the pg gem, but not with MySql) the implementation of queries like Foo.where(id: [1, 2, 3]) changed from SELECT "foos".* FROM "...
1
vote
2answers
32 views

Rail convert array into group

I am trying to convert one of my array into some format where it can convert itself into table format. I have an array which is: [ { id: 1, Revenue_Account: "Revenue Receipt", ...
0
votes
0answers
26 views

Error connecting Ruby with SQL Server 2005

I am trying to connect SQL Server 2005 with Ruby using this code: con = DBI.connect(DBI:ODBC:"SQLNCLI.1":"DESKTOP- PA2K41U\SQLEXPRESS";"ruby_ch") sth = con.prepare("SELECT * FROM tbl_test1") ...
0
votes
1answer
33 views

Accessing parent object from child object in rails?

I have three serializers, nested within each other. Like this: class PersonSerializer < ActiveModel::Serializer attributes :id :name has_many: companies class Company < ActiveModel::...
0
votes
0answers
7 views

How to debug Rails project with angular 4 in Visual Studio

I want to debug Ruby on rails project, having angular4 on UI side and rails as a server. I followed many documents but I am getting a error "Could not find the task 'npm'. when I try to run the ...
1
vote
2answers
10 views

How to show only articles written by users themselves through Devise in Rails

I'm using full_calendar to show events based on user id. I have an index of home that renders _form.html.erb of events, and creates events here. And when I moved to the events/index with the ...
0
votes
2answers
31 views

SyntaxError: Unexpected token '&'. Expected a property name

I'm using Slim. When I describe a javascript: block, I use this inside the JS code: javascript: var tteesstt = #{users.select(:id, :email).order(:email).to_json}; But I get this error: ...
0
votes
1answer
39 views

Better way to add configurations files in Ruby?

I have an application in ruby, that I want to make some configurations. For example, in development, I want that a user can add only 10 photos on an albun for a certain plan. Something like this: ...
0
votes
1answer
28 views

Automatically parsing date/time parameters in rails

Is there a way to automatically parse string parameters representing dates in Rails? Or, some convention or clever way? Doing the parsing manually by just doing DateTime.parse(..) in controllers, ...
0
votes
1answer
22 views

Rate a post only once per user in rails

I have facing trouble in allowing users to rate a post. My task is to enable the user to rate a post only once. On the show page, the post i have includes radio buttons for rating. If the user tries ...
0
votes
2answers
28 views

get the object value using ajax in rails

I am new to Javascript and rails so please consider that I am not really good at this. I have basic ajax calls ajax: $.ajax({ type: "get", url: "/url", data: $('#somedata').serialize(), ...
0
votes
0answers
16 views

How nice to display logs?

I use gem "Logs" to display logs. And I would like to display logs as shown in this picture. Simply at the moment I have logs, and at the bottom of a bunch of pages without normal pagination. This is ...
-2
votes
1answer
23 views

How to get submitted form data into a dynamically created csv with download button. [on hold]

Whenever user will submit form data then submitted form data will store in dynamically generated csv and user can able to download that csv.
0
votes
1answer
31 views

Sum up the total of a field in ActiveRecord using inject in Ruby/Rails

Help me understand this ActiveRecord error, and also please tell me the right way to write this. I have a Payment model class Payment < ApplicationRecord enum status: %w(success, failed, ...
1
vote
1answer
22 views

rails engine ckeditor image upload causing exception

I have created an Engine including CKEditor. Within my dummy application the form.cktext_area is working and rendering fine, however when I try to upload images I get the following exception: ...
0
votes
0answers
25 views

Unable to viewing SQL records & DB schema on terminal using rails db:console

I'm building a small rails app as a backend for the API calls I make from my react native app. I've built a post request in the react native app that posts data to the DB. I'm having a problem though ...
0
votes
1answer
23 views

Forbid the user to open image in the new tab (Rails app)

I display the image in my Rails app like this: = link_to image_tag(image.url), image_path(image.id) I want to forbid the user to open this image in the new tab. How do I achieve this?
-1
votes
1answer
23 views

ruby on rails - Sorting by count product column in categories

Pls tell me how to sorting by count product column in categories. My category.rb: class Category < ActiveRecord::Base has_many:category_products has_many:products, through: : category_products ...
0
votes
2answers
25 views

rspec - Check if array contains element with specified ID

My controller method returns an array and I intend to check if an element with specific ID is included, something like: expect(json_resp["animals"]).to contain_element_with_attribute(:id => 4)
1
vote
0answers
19 views

Rails render as js toggle modal -> unrecognized expression

I'm trying to toggle a bootstrap 4 modal when an entry got updated successful. if i do it manually from the chrome console, it does work fine but from within a js.erb template file it just throws the ...
0
votes
0answers
24 views

Import task for non-standard key referencing

The association of two classes as such, class Available < ActiveRecord::Base belongs_to :structure, class_name: 'Structure', foreign_key: 'product_code' class Structure < ActiveRecord::Base ...
0
votes
1answer
21 views

No command “rails test” in my Ruby-on-Rails application

I've recently joined a team on a Ruby-on-Rails application, and I try to audit the tests. There were no tests, so I decided to implement them in the app. After seeing around what was there, I have ...
0
votes
0answers
8 views

wicked_pdf create hyperlinks to local files in downloaded PDF

This question is an extension to this one. The first problem is that using the file:/// protocol one can only define absolute paths. You could, however, use HTML links with absolute paths instead, e....
2
votes
2answers
32 views

Customize Devise Passwords error message

I've a project that implements devise and I'm having trouble overriding the Passwords controller's messages. When a wrong email address is entered by the user, Devise by default gives Unable to find ...
0
votes
1answer
33 views

How can i use complex direct query instead of activerecord in a rails application?

I have one rails application, which has one function that read values from database using active-record like this way def get_all_products products = Product.for_locations(location_id) products....
0
votes
1answer
16 views

Return JSON response for errors when request's content-type is JSON

I have a rails application that renders ERB's and also a separate namespace for API endpoints. When there's an error, say 404, or some un-rescued exception...etc, rails is returning errors in HTML. ...
0
votes
1answer
31 views

How can I access Rails variable in Javascript?

I have a Rails variable that I need to pull all the dates and time (send_time) and put into a JS array. I am trying to use the JS array of sent_times to block users from using those date/times in the ...
0
votes
1answer
36 views

How to serialize nil to JSON as nil, not an empty place?

In my controller/action I have some values that are nil def my_action @var1 = get_boolean_value || nil @var2 = get_int_value || nil @var3 = get_string_value || nil # there many more, any one ...
1
vote
0answers
47 views

To create roles and permission dynamically in ruby on rails

I am working on a Ruby on rails project. There are 5 Tables such as user table; role table; permission table; user_permission table; and role_user table. Using a Current User ID, Here Super Admin ...
0
votes
2answers
23 views

Ruby Gem .gem is empty after 'gem build'

I used Swagger CodeGen to generate a Ruby client for an API. Here is what the resulting .gemspec file looks like: # -*- encoding: utf-8 -*- # =begin #convertapi #Convert API lets you effortlessly ...
0
votes
0answers
25 views

An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue. macOS High Sierra

I'm getting the following error when running bundle in Rails, using macOS High Sierra 10.13.4. Have tried running: brew install mysql sudo gem install mysql2 Which seem to be the recommended ...
0
votes
0answers
20 views

Rails 5.2 asset helpers not including fingerprint digests

I am in the process of upgrading our product from rails 4.1 to 5.2. I'm hung up on what appears to be an asset pipeline related issue. When I load the app in our browser, I see the following error in ...
0
votes
0answers
31 views

Testing a quiz application that requires audio responses

I have a quiz application, which has audio questions and answers. I am using howler.js to play the audio questions, and using MediaStreamRecorder.js to record the audio responses. These are uploaded ...
0
votes
2answers
40 views

Rails validations and initializations with interdependent fields

After coding in Rails for a couple of years, I still don't understand the Rails Way for more advanced concepts. The Rails Way is so specific about convention over configuration, however when you get ...