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)

1
vote
1answer
35 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
44 views

Find existing session

I have this method in my rails app: ...
0
votes
0answers
5 views

Best way to build a JSON API coupled with HTML views in a Rails project [migrated]

I've got a Rails eCommerce project communicating with an iOS app. The iOS app receives JSON data from the Rails back-end, but there's also HTML rendering when a user comes to the project from his ...
2
votes
1answer
58 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
25 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
125 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
49 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
87 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 ...
1
vote
0answers
21 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
59 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
85 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
40 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 ...
0
votes
2answers
50 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
79 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
34 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 ...
3
votes
1answer
80 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
28 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
34 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
27 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
49 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
47 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
150 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
57 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
31 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
29 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
33 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
22 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
57 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
72 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. ...
2
votes
1answer
53 views

Truncating article text

I need to show article's content based on this logic: if article's content has to be truncated (e.g for preview) if there's [read more] substring in the content ...
3
votes
2answers
56 views

Show all records when current user is admin

I have the following. How best to refactor it: ...
1
vote
2answers
41 views

Creating a percentage complete method for a form

I am a relatively new Rails developer and doctor doing research. In my Rails based research projects I often have questionnaires for which I provide a "% complete" parameter. Here is an example. You ...
3
votes
1answer
30 views

Classes for attributes validation

I have two classes responsible for attributes validation: ...
1
vote
0answers
13 views

Method for adding a product with product attributs to cart

Currently I have an app that have many stores. Each store can have several products. Whom again can have many product attributes assigned to them. For instance a shirt is a product, and size and color ...
0
votes
1answer
52 views

Using as few queries as possible for many table associations

I have a table containing about 30k rows of data and there's several table associations. The problem is that there's like 18 columns, and each column requires 1 db query. Here's an example of what ...
0
votes
2answers
42 views

Duplication of enum across two models

In my Rails app, I have two classes each with the same enum for status. Code climate is complaining about duplication. ...
2
votes
0answers
30 views

Formatting a long HTML document in a model method

I was asked to make a view which is a mix of HTML & ERB logic available in multiple views. At first this seemed pretty simple. However, some of these views required the output to be plaintext ...
4
votes
1answer
34 views

Three identical AJAX button handlers in three views

In my Rails 4 app I have this event listener: ...