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.

0
votes
0answers
7 views

Updating one model field based on the associated model's field

I'm wondering if there is any way we can optimize the following code. Scenario is Library's active field should be ...
1
vote
1answer
38 views

Ruby on Rails quiz function

I have created a quiz function in my rails application. Since I want to track responses and make it a server-side application I created a table to record the responses of the questions people answer. ...
1
vote
0answers
31 views

TDD for Ruby On Rails API for group event items

I found myself working in this coding exercise for a work offer. I tried to apply TDD in the process but I didn't get any feedback from the company and I really would like to know what can be improved ...
1
vote
0answers
23 views

A Ruby on Rails controller and JS code to add labels to products, like Gmail's labeling tool

My friend asked me to write a tool that lets users bulk add/edit labels (taxons) to store (spree commerce) products. I came up with this, curious to know if you guys find the code readable/...
1
vote
1answer
41 views

Showing a message when the column is true

I'm making an app using Rails. I have 4 Boolean columns in a table like below, and I want to show a message if that column is true. ...
-1
votes
0answers
15 views

Connecting to DB2 using Ruby on Rails

I need to connect to a IBM db2 table using jruby and Ruby on Rails. I have managed to do it, but I haven't seen this solution anywhere and I am hoping I can get some feedback on it, or if there is a ...
2
votes
1answer
66 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
28 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 ...
2
votes
2answers
55 views

Modelling football teams and fixtures in Ruby (as compared to SQL)

I am trying to model information around football teams and fixtures. I am using the Premier League fantasy football API for my data. The fixtures API is here, and the team data (along with a lot of ...
3
votes
0answers
76 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
56 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
91 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
94 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
15 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
45 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
47 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
132 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
55 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
96 views

Model Association (Rails 5 API)

I have a Character model that has a CharClass and ClassPerks child. Currently I am ...
0
votes
0answers
48 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
88 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
366 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
164 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
112 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
362 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
487 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
54 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
174 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
77 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
91 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
98 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
74 views

Rails model for publishable posts

I'm trying to dry up this Rails post model: ...
1
vote
1answer
85 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
36 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
456 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
1k 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
202 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
2answers
181 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
564 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
48 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
453 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
846 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 ...