Questions tagged [ruby-on-rails]

Ruby on Rails is an open-source web development framework written in Ruby. If your question code is written in Ruby on Rails, tag with Ruby as the language tag. Many things are defined by convention, freeing you from having to re-invent things to stay productive.

Filter by
Sorted by
Tagged with
0
votes
1answer
152 views

Update the frequency of Sidekiq job

I'm working on a feature which user can set frequency of a job. I am using Sidekiq. My solution is when someone updates the frequency from view, I will delete all old scheduled jobs and create a new ...
2
votes
1answer
1k views

Rails passing in params to association on create method

I am currently using a belongs_to relationship in my Rails application to link a map and a group an object that way I can assign those maps to the user based on the ...
1
vote
1answer
427 views

RSpec test for handling known IP addresses

I want to replace the array of ips with a method (like known_ips or just ips) but I don't know how. I'll use this ...
6
votes
3answers
176 views

A method that calculates win streaks

Right now, I have the following: A win_streak column on the User table. This method in ...
3
votes
1answer
1k views

Shopping cart in Rails for karaoke items

This is my first cart implementation in Rails so I wanted to get some feedback on the correct method to implement it. First of all, I am storing the data directly in the session because the items in ...
3
votes
1answer
62 views

Ensure multiple steps work/saving multiple models via a service

I just thought of something new re: saving multiple objects in Rails (though Rails is not necessary). Objectives: Create an author and a tomato, but both of those must be valid. If invalid creation, ...
1
vote
0answers
206 views

A rails controller needs to validate certain values exist

I need to pass some values from a CMS to a rails view. I should check these values are defined in the CMS. These values are meant to be use in all pages, hence the use of ...
2
votes
1answer
134 views

Init.d script for Rails managing a Rails app via Unicorn

This script is to enable the remote management of a Rails app via one script. I pieced it together from various blog posts. I am not to familiar with some of the BASH functionality that is used. It ...
3
votes
2answers
46 views

Saves files and attachments regardless of errors in the model

I have a long form with dozens of fields, and users can upload photos and attachments in the form. It's super annoying when there is a simple field missing, the record doesn't save, and the user has ...
0
votes
1answer
120 views

How to refactor this function to solve cyclomatic issue? [closed]

I'm trying to fix this error on codeclimate Cyclomatic complexity for resource_icon is too high. [7/6] What is the best way to refactor this function? ...
0
votes
1answer
554 views

Add values to multiple keys in one line

I Have orders table, every order has different payment method and made by different user, has different total of money. and i want to make a detailed report, i export date as a hash to the views, as ...
1
vote
1answer
102 views

Rails model for publishable posts

I'm trying to dry up this Rails post model: ...
2
votes
1answer
103 views

Rails 5 helpers to fetch tasks with different filters

I moved a lot of the loading/logic from my view to my controller, and it's working great but after I did this I now have several very similar helper methods in my controller. What is a more efficient ...
0
votes
2answers
37 views

ActiveRecord query for coaches a client has bookmarked

I'm trying to figure out the best way to set up an ActiveRecord query. Models There are three relevant models involved: ...
0
votes
2answers
34 views

Counting number of messages for a mailbox over several periods

The idea is to return a number of messages received today, this week, this month. ...
0
votes
1answer
124 views

Creating a nested treeview Rails

I have a dataset that looks something like this: ...
2
votes
1answer
2k views

Rspec unit test for updating a property of a model

I know how to write simple RSpec tests and unit tests. I just want to know if this is good enough or if there are any improvements I can make. I intend to test the the ...
1
vote
1answer
44 views

Refactored code for updating user password, email and other info

I have to update user email and password if they are present in the params, I have other user information also which can be updated. this is the method I have written, but it doesn't seem like a good ...
2
votes
2answers
2k views

Rails Way for dynamic link_to

I have a drop-down that users can choose what template they are about to receive. I'm pretty novice to Rails but I kind of go the logic Front-end = JavaScript and ...
1
vote
2answers
206 views

Resetting a password

I am trying to reset a password when password_reset_token is received in the controller. But it's becoming a long if ...
2
votes
2answers
287 views

Log in to Rails app using Facebook SDK

I have built a Rails app where users can login using Facebook. They have an account on the Rails app but do any authentication in it other than creating a session if they have logged into Facebook ...
0
votes
2answers
55 views

A class that uses a few other classes to generate an email

I seem to find my self writing a lot of classes like the below where there seems to be some kind of send method that just calls a bunch of other methods. Is this ...
2
votes
0answers
781 views

Rails CRUD feature specs (RSpec and Capybara)

The following feature spec tests CRUD operations for the users resource in a Rails 4.2.8 application. It includes tests for filtering, sorting and pagination ...
0
votes
1answer
58 views

rails method for transaction type

I am trying to make a rake task but after completion my code i realized i need some refactorization. How could I do refactorization of the following code? ...
2
votes
1answer
664 views

Rails5/Devise/Omniauth (Multiple Providers)

I spent the better part of the last two days getting this to work, but it finally is working, but it feels extremely redundant. I am following a belongs_to method ...
1
vote
0answers
79 views

JavaScript client using a REST API to edit a playlist

I wrote some Javascript code today to interface with a restful Rails app which I thought was rather awkward & took me far too long to write. ...
5
votes
1answer
1k views

Rails & RSpec - Testing API with request specs and shared examples

I have written the following shared examples which are used in multiple request specs to test a namespaced RESTful JSON API. Application details: Rails 4.2, RSpec 3.5, Devise for authentication and ...
0
votes
1answer
55 views

Ruby class to encapsulate Retrying (for instance, with email)

One of my clients sends quite a few emails a day ... I would think over 500. They are mostly reports to clients or employees. The volume has become sufficient that intermittent issues with gmail (like ...
4
votes
2answers
72 views

User and picture models

I have the following models: User Picture Variant User has_many pictures, picture has_many variants. Variant has value price ...
3
votes
1answer
523 views

Controller tests (Rails 4.2 and RSpec 3.5)

The following code is a controller spec used in a Rails 4.2 application with RSpec 3.5. I would greatly appreciate your suggestions on how to improve it (e.g., efficiency, readability, maintainability,...
3
votes
2answers
873 views

Group array by sums

I have the following code that takes an array, and groups it by the sums of its elements: ...
1
vote
2answers
50 views

Weekly job to create or update the lessons in all locations

I'm working in a project with the following structure. A location can have many timetables with many lessons. I need to perform a job in all locations every sunday to create or update the lessons. <...
3
votes
0answers
228 views

Ruby on Rails portfolio website

I've been learning Ruby on Rails for the last few weeks. I've decided to do a portfolio website using Ruby on Rails to showcase all of my projects. Can you look through my code to see what you think? ...
1
vote
1answer
465 views

Extract list of selected contractors by matching serialized array in Rails

I'm working on an application where I have a Company model setup as follows: ...
3
votes
1answer
322 views

Ruby wrapper for Instagram API

I've created my first gem as Instagram API wrapper https://github.com/agilie/instagram_api_gem. I would be very pleased if you give me some feedback on code organization, methods elegancy and so on. ...
4
votes
7answers
2k views

Display related records, if they exist, in Rails view

Is this much logic in view is justified to check for the presence of record? ...
1
vote
0answers
832 views

Unit-testing authorization policies in Rails with RSpec

The following specs test the authorization setup of the Post resource in a Rails 4.2 application. The Pundit gem is used for authorization but I believe the specs ...
1
vote
3answers
2k views

Count has_many relationships

I have 3 models: Import, Product, Values. An import has_many products. A product has_many values. I want to find the product with the highest values count and the sum of all values for all those ...
1
vote
0answers
232 views

Rails - updating and deleting exactly 2 children of the parent model

Requirements A Phrase can have many Translations, which are in turn a Phrase; thus, the ...
2
votes
1answer
379 views

URL whitelist class

I'm trying to make a class for safe redirection of URLs. Redirecting URLs is something you can have in a get parameter, for example: ...
3
votes
2answers
67 views

Rails method to match users according to language fluency level

This code works fine, but I'm still learning, and feel like there is a more Railsy way to write this. Is there a good rails ActiveRecord method I should learn more about? Please let me know if you ...
2
votes
2answers
62 views

Persist relation to a class (and not a class instance) in Ruby on Rails with Mongoid

Assume my users can subscribe to several plan_types. I want to define those plans as classes, and be able to keep, for each user, a reference to a subscription_plan and also a presubscription_plan. ...
0
votes
1answer
46 views

Checking whether any of some large collection of attributes has changed [closed]

I have to check a large number of attributes and do something if any of them have changed. However, right now there are way too many or statements. Is there a better way to do this? ...
1
vote
2answers
2k views

Setting unique code to model before creating (ruby/rails)

I have a Table model that needs a unique code. I have a method creating the code (and making sure it's unique), but I have the same line ...
0
votes
1answer
104 views

List User Online Status

I'm using Rails with MongoDB for database. In my apps I have 1 action for displaying list of users. User has name, image, ...
1
vote
1answer
133 views

Ruby on Rails Messaging board

I would definitely love some feedback on this message board app I made. I been doing front end development for the most part and I just want to keep my backend chops up. Let me know anywhere that can ...
1
vote
0answers
40 views

Calculate time to the offset of another time zone

I have a time stamp with UTC +0, i.e. time_stamp = Sat, 08 Apr 2017 16:01:16 UTC +00:00 I'm converting the time/date part of the time stamp to another time zone'...
0
votes
2answers
2k views

Cyclomatic complexity for method is too high

How do i refactor my code to fix the lint error i am getting? ...
2
votes
0answers
499 views

Module to dynamically generate controller concerns

I'm rebuilding a Rails project from when I started developing, and I wanted to figure out how to really DRY my controllers out—without making them unreadable by doing half/all of the work in a ...
2
votes
2answers
73 views

Build Hash with 2 input variables

I have a case that looks like this : John has 120 candies, He needs some plastic bags and marks each plastic bag with the number and puts 50 candies in each bag. So John can only fill up to 3 plastic ...

1
2
3 4 5
12