Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-2
votes
0answers
8 views

Two GET methods with different query parameters : REST [on hold]

I'm working on a rails project, where I have a Transaction model. This model has a id and a ...
0
votes
0answers
15 views

Join model that constantly has to reference parent(s)

I have a situation where there are restaurant dishes that can be served at many different locations. An example would be somewhere like McDonalds where the Big Mac is served at locations nationwide. ...
2
votes
1answer
60 views

Rails thin controller method to change account plan and fire slack message via a service object

I'm a beginner with Rails and am trying to figure out how to keep my controllers clean and thin, and how to work with service objects. I am building an internal tool to manage our SaaS customers, and ...
0
votes
1answer
26 views

Pyramid of doom Grape endpoints

I'm creating an API endpoint to create and delete associations, essential creating and deleting records of a join model. The code below doesn't seem idiomatic or pragmatic at all. What's the best way ...
0
votes
0answers
35 views

Rails mixin to handle address fields

I'm currently working on a Rails 5.2 application where I'm trying to parse users data into a PDF form. The data from the user is received via a JSON object. The fields of the form are as follow: <...
3
votes
0answers
70 views

Implementing secure API for use between other internal apps

My team and I are trying to implement a secure API and would appreciate some feedback on the following: If there are areas of improvement in the current code to improve security Recommendations on ...
1
vote
1answer
54 views

Creating an associated object on create/update

My app is setup where there are musical artists and albums have message boards through a has_one polymorphic association. ...
3
votes
0answers
90 views

Retrieving data from the movie database

I am trying to retrieve the series, seasons and episodes from the movie database, however I am pretty new to Ruby on rails and I feel like what I am doing could be improved a lot. I use an ...
2
votes
2answers
80 views

Rails controller for a vocabulary quiz

I'm new to refactoring and I have just refactored an old Rails project that had bloated controller methods. I spun off the bloated methods into its own separate controller following this logic, since ...
0
votes
0answers
28 views

Creating join table entries based on different connection ids

My controller code is: I'm using callbacks to find @lead. ...
0
votes
0answers
14 views

Grab and kill AMQP subscriber

I am using amqp client in order to get data. I am using sidekiq jobs in order to make sure that client is always connected and getting data. ...
2
votes
2answers
43 views

Distinguishing between people who have likes to posts and those who have dislikes

I want to distinguish between people who have likes to posts and those who have dislikes. I want to find a way to improve my code without thinking it is efficient. ...
1
vote
2answers
46 views

URL Routing Application

In a Ruby on Rails application I want to have this routing: for URL www.example.com/reports go to controller documents and action ...
0
votes
2answers
86 views

Ruby on Rails application controller

My application controller keeps growing with small helper methods that I use in both my controller and views, is it okay? or what do you recommend doing? ...
2
votes
0answers
51 views

Counting how many questions in each category are tagged

I have a homepage that shows how many questions are in a certain category which is done through tagging. The functionality is working great, it tells me how many of each there are. However, newrelic'...
0
votes
0answers
32 views

Rails db query to pull joined and included data

I have a conversations controller which is used to pull all the conversations for a user of type seller. Sellers can have <...
3
votes
1answer
77 views

Model Association (Rails 5 API)

I have a Character model that has a CharClass and ClassPerks child. Currently I am ...
0
votes
0answers
47 views

Rails view to display optional text

I have been using rails for a little while now and have read a few articles that talk about removing as much logic from your controllers as possible. I have a maps object with the following schema. ...
0
votes
1answer
82 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 ...
1
vote
1answer
246 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
139 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
99 views

A method that calculates win streaks

Right now, I have the following: A win_streak column on the User table. This method in ...
0
votes
0answers
292 views

Rails Strong Parameters Filtering

In my Rails controller with strong parameters, I have the typical my_model_params private function to filter out any "scary internet params". One of the parameters ...
3
votes
1answer
363 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 ...
1
vote
1answer
53 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
161 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 ...
0
votes
0answers
58 views

Add title and description to existing Rails User model

I'm a Rails newbie who need advice on strategy for routing and such for some Rails attributes...my very first hand-made attributes. What I have works, but I'm pretty sure there's a better way to do it....
2
votes
1answer
70 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
42 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
85 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? ...
1
vote
1answer
85 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
72 views

Rails model for publishable posts

I'm trying to dry up this Rails post model: ...
1
vote
1answer
78 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
1answer
35 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
32 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
68 views

Creating a nested treeview Rails

I have a dataset that looks something like this: ...
2
votes
1answer
317 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
39 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 ...
1
vote
1answer
805 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
201 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 ...
1
vote
1answer
141 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
50 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
530 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
46 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
420 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. ...
2
votes
1answer
774 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
45 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
69 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
309 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,...