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.

learn more… | top users | synonyms (1)

2
votes
2answers
29 views

Client categorisation based on hourly payment

I am currently working on a small internal rating system for clients to be able to prioritise my work based on what client pays best. The input data is the hourly rate they are paying and based on ...
0
votes
0answers
9 views

Polymorphic event notification model in Rails

I have a polymorphic notification model. When user gets a notification he can get on the page of the notifiable to check out what happened exactly. For instance ...
1
vote
0answers
12 views

Install ruby using rbenv in bash script

I want to write an automated bash script for installing ruby and rails using rbenv. But I am getting issue of session reload in terminal. My bash script:- ...
-1
votes
0answers
45 views

A long form to collect business information

I have a long form which includes many nested forms. I have tried to use partial but I believe partial is not working, and the object is not being transferred there. Any help with this will be ...
4
votes
1answer
35 views

Generate dyamic 'week of' date range

I was in need of a method to dynamically generate a week range, so that the view reads something like "Week of May 16 - 22" and updates automatically. Here's the helper method I came up with, but I'm ...
4
votes
1answer
45 views

Displaying information about a ticket purchase

My code works perfectly, however, I know my approach isn't best practice practice. I would appreciate the effort of anyone who tries to explain in details on how I could refactor this code using ...
1
vote
1answer
35 views

Recursive categories fetch and view

I have categories and subcategories in my view. The code looks like this ...
3
votes
1answer
56 views

Determining whether a task is active based on many conditions

I wrote a Rails model instance method that checks many separate conditions, and returns a single boolean. It does not employ any nesting of branching structures. Each check has its own comments ...
1
vote
1answer
33 views

Old and new shouts controllers

I have a photo_shouts_controller.rb and text_shouts_controller.rb which both have almost similar implementations, and I would like to refactor it. I have implemented a refactoring but I am not too ...
0
votes
1answer
30 views

Rails create create default database records

In my application I have an accounts model: class Account < ActiveRecord::Base belongs_to :user has_many :invoices end The ...
1
vote
1answer
59 views

Conversational bot architecture

I am currently building a small conversational bot, and I am struggling with the architecture. I use Facebook Messenger combined with Wit.ai's API and a Shopify store API. My rails app is the ...
3
votes
2answers
57 views

Find existing session

I have this method in my rails app: ...
2
votes
1answer
62 views

SE-like voting system

I've created a voting system that's similar to Stack Exchange's in a Ruby on Rails web app. It's working great - as far as I can tell, all the edge cases are caught. This is the action to cast a vote. ...
0
votes
1answer
30 views

Get properties from all children in a recursive SQL structure

In our product, Company is a model that can have many Companies belonging to it; so some Companies are parents, some are children, and many are both. We have a ...
3
votes
3answers
153 views

Check if a store is currently open

This is the dirty bastard of my current code block, and I'm trying to find a way to improve this code for increased readability, but also functionality. The method checks if the store is currently ...
2
votes
1answer
53 views

Update record with CSV

I'm using Rails 4.2.5, and I'd like to update existing records with a csv file with two fields: id,category. Where if the category field is blank, it defaults to misc. Here's an example csv file: ...
4
votes
2answers
96 views

Optimize the CSV Upload function in Ruby On Rails

The code is working fine however, I would like to fix code after unless and can I store thread ID in the database too? Is there a way to improve performance? ...
2
votes
0answers
19 views

ActiveAdmin menu-generating mixin

I've written an ActiveAdmin mixin, such that you can include it and call simple_menu_for Foo, to reduce duplicate code when working with simple models. Here is the ...
2
votes
0answers
27 views

Custom bang! method and Rails validation

I have a model called booking. ...
0
votes
0answers
18 views

Simple app which allows to create posts and delete them by a password

Whole thing you could find here There is no validation, i know. Main page: ...
1
vote
1answer
71 views

Refactor code to solve the 'Line is too long' error in rubocop [closed]

Method.create(domain_id: domain.id, type_notification: type, message: title, url: url, owner_id: self.user.id) How can I reduce this line to 80 ?
8
votes
2answers
93 views

Error-testing be with cucumber/capybaraweb

I'm working on writing tests for a rails application using cucumber and capybara. I have a scenario for a user editing a post, and making it invalid. The scenario looks like this: ...
1
vote
1answer
22 views

Mini Test testing save on one and many trips

I know there is a balance to be struck between writing dry code and damp code but I have the feeling that this is a bit too repeative. Is there a terse yet self explainatory way to rewrite these ...
3
votes
2answers
42 views

Ruby method that is validating the payload received

What is a cleaner and/or clearer way of writing the following method ...
2
votes
1answer
41 views

Count associations in a Ruby model

I'm trying to figure out if there's a better way to run the code below. Basically Course is an association of Student and ...
2
votes
3answers
77 views

Notify owner of post and other commenters

I have a rails4 app. When a user comments on a post it should send a notification to all the guys who commented on the post and to the post creator. I have a working method in the controller, but it's ...
1
vote
2answers
82 views

Controller method to manage SMS subscriptions

I have a huge method in my controller that is not DRY and just could use some general TLC. I'm new to ruby and I have not refactored my own code before, only contrived code you find on tutorials. ...
2
votes
1answer
36 views

Changing a user status flag, with validation

I am writing a function which on update of any attribute of model sets the status of variable is_kyc_verified to false. Here is the code of the User model and the ...
4
votes
1answer
104 views

REST API with Ruby on Rails and ReactJS

I'm currently working on building a simple REST API using Ruby on Rails. I noticed that a lot of the things I did were a bit redundant, especially the models. Just to clarify: I want this to be a REST ...
0
votes
0answers
33 views

Responsive photo gallery using Flickr API

This began as just a simple sidebar widget and evolved into what you see here. I'm pretty happy with the results but the photos take a long time to render and sort out on the page. Is this mostly ...
3
votes
1answer
36 views

Simpler method to find users in child categories

I am using the ancestry gem to organize my post categories tree. I have 8 parent categories, and they all have many child categories. To retrieve an array of child categories, I use: ...
1
vote
0answers
28 views

Generating a Postgres query dealing with creating a time series

I want to sum the number of my published publications model in a given interval and return a time series. (related SO) The main challenge is that I want the code to respect the time zone passed to ...
0
votes
0answers
8 views

Robustly send notifications from multiple processes

We have Notifications stored in a notifications table, which is worked on by multiple background workers. The notifications table has these relevant attributes: id (primary key, unique) send_at ...
4
votes
0answers
51 views

Seeding a database

I'm seeding my database with really complex code as I think. It works but is not good. Constrains: Every meal has exactly ONE main dish (marked as is_main in ...
1
vote
1answer
48 views

Removing folders from my rails app with rake

I'm trying to remove the tmp/letter_opener folder. Everything works fine, just wondering if there's a better way to write it. My next step is to write some tests, ...
4
votes
2answers
178 views

Ruby method that returns an age from a date of birth

I have a method on my user model to calculate the user's age and return a human readable string. My user's can be between 1 month old and above so the returned string is different depending on if the ...
3
votes
1answer
75 views

Displaying a Google map with multiple complex markers and unique info windows

This JavaScript file is part of a large Ruby on Rails app. Any feedback is appreciated. Update 3.7.16: as per @Jonah's suggestion, here's a description of the code's purpose: I've built a ...
2
votes
2answers
41 views

Shipping address validations

In my journey of learning Rails, I'm wondering if I should test model validations. If so, is this a correct way to do it? ...
1
vote
1answer
45 views

Updating an auto-generated invoice (future) when current plan changes

I've built-out a mechanism to go and find an auto-generated invoice and update it with new information when a plan is changed or if users are added to the plan for the current billing period. It will ...
0
votes
0answers
27 views

Testing the integration of a complicated system

I'm trying to write tests for a recurring billing system. I want these tests to show that the functionality of the system works when put together - I have lots of unit tests, but I wanna make sure ...
2
votes
1answer
30 views

Generating sample data for a Rails application

I am working on generating sample data for my Rails application. For now we will just be using the sample data while we are designing the website. I'd like it to be as easy as possible to generate ...
1
vote
1answer
36 views

Order list of movies and save sorting in cookies

I did this project and I'm going back over it and trying to optimize some stuff. This is the movies_controller.rb file, which is basically a table that I need to sort based on user parameters. What I ...
2
votes
2answers
54 views

Checking days from now

I'm trying to respect the Ruby principle of keeping my code dry; however, in my conditional, I have different constants set to different days. But that's the only thing different. They're pretty much ...
3
votes
0answers
23 views

Updating ActiveRecord with text from a joined table

I have an Active Record update with the following data model: TvMenuProfile has one rich_text_special ...
1
vote
1answer
46 views

Establishing parameters for a sales report, with default boolean and date values

The idea is that I am getting the params from a GET request in the form of a Hash (symbol→str) and I want to transform them into dates and booleans. For that ...
3
votes
0answers
100 views

Custom MySQL duplicate_key update queries

The goal is to create an activity or update its counter if it's already present. And to be super accurate, the code avoids race conditions with a custom ...
1
vote
1answer
65 views

Rake task to send users a reminder to post with conditions

I am implementing a feature that reminds users to make a post via email if the user has set daily reminders to true he has not posted yet today and if the current hour matches when he would like ...
1
vote
1answer
84 views

Testing a Rails API controller

I'm building a JSON API. I'm writing my controller tests so that they compare the response body to actual JSON I'm generating in my tests using ActiveRecord. I wrote two helper methods that make the ...
3
votes
1answer
43 views

Checkboxes array to delete images

Basically I'm displaying an array of images on a page with checkboxes. The idea is when a user is editing a post and the checkbox is checked, the image will get deleted. Each image also has an ...
3
votes
0answers
45 views

Fat Controller Action - Deep nested filters

I have this really really long controller action and would like someone to help me break it down. ...