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
4
votes
2answers
50 views

Retrieve next card(s) base on the provided parameter

How can I remove the duplicated params[:next_cards]? ...
2
votes
2answers
470 views

Update single common column in multiple has-many relationships rails

I want to update a single column in 4 tables. All relationships are has-many among them. Private schools has many private classes Private classes has many lesson plans Lesson plans has many quizzes ...
2
votes
0answers
27 views

mapping event uuids to events in ruby

I have quite an interesting challenge for you today. The following code will produce a map with events as values and event uuids as keys. I've also listed out the spec for it. I would like to know ...
2
votes
1answer
521 views

Handling ajax responses in Rails

I have the following method which creates a like for a post: ...
2
votes
2answers
2k views

Rails like and unlike posts

I have the following two methods which handle the liking and unliking of posts in my Rails application: ...
0
votes
1answer
457 views

Displaying job status in a jQuery Datatable

I was wondering if there was a better way to write this: ...
3
votes
1answer
2k views

Array of date by each week

I have two dates, example : date1 = "4-02-2017".to_date date2 = "4-02-2017".to_date + 29 I try to get array of date by each week with this : ...
2
votes
1answer
61 views

Displaying model statistics (as a sentence) in a view

A Rails 4.2 app has three models: User Author Quote ... and the following associations: users HABTM authors author has_many quotes If the user is associated with any authors, his "profile" view ...
1
vote
0answers
40 views

Use of data-custom-value to recover data

Necessary explanations The code below deal with the relationship between my question and test_case model. A question ha many ...
2
votes
1answer
209 views

Listing employees, categorized by license expiration date

I am working on a personal project and I have hit a wall. I know I am writing bad code and I really want to refactor the code below. The application has three tables on the same page. Each table ...
1
vote
1answer
217 views

Use an existing invoice if one exists, else create one

Here are the requirements: If initial_invoice? is false, existing_invoice always exists. If ...
1
vote
1answer
78 views

Rails Calendar Generation Method

I have this helper method that generates an HTML calendar based on the current day: ...
2
votes
1answer
1k views

Replacing the vowels of a string with the letter “X”

This code replaces every vowel of the string with "X": ...
1
vote
1answer
49 views

Create a SelfJoin with has_many

I am trying to do a self-join. I generated this migration to make a correct primary. This code works, but I'm not sure if this is the best way to do things. ...
5
votes
2answers
917 views

Rails API for communication between two Rails app where the former app posts data to the latter and the latter return a response

The Controller code for the first app to post data to another app ...
1
vote
0answers
22 views

Creating a list of things by looking up multiple sources

I am trying to write a rspec webmock test for a rails PORO model. What this model does is, query bugzilla with a set of filters for a list of bugs and iterate over it such that: The bug ids are used ...
1
vote
2answers
100 views

Class/model hierarchy for a school-management application

Please find how I would model a system that had teachers, students, classes and parents. Instead of creating a model for each user type, I created only two models, ...
0
votes
1answer
57 views

Validating only attributes that are present in a form [closed]

I want to skip validations based on attributes. If certain attributes are not in form so I do not want to validate them. Currently, if I post them from one form which has 1 field, it still validates ...
-1
votes
1answer
74 views

How to run this code faster

This sample code is correct and no error however this only good if you only have few hundreds or thousand datas but if you have million queries this takes time how we can improve this algorithm ...
3
votes
2answers
200 views

Build a pizza and choose your toppings

I've created a scenario below, in which a user can build a pizza and choose their toppings, then order their pizza: ...
3
votes
1answer
63 views

Helper that swaps out some text for certain icons

I have a Rails helper that swaps out some text for certain icons. Example: Helper Sample ...
1
vote
1answer
47 views

Finding users who liked a post

I have a method liked_by and it doesn't seem like appropriate as per Ruby style. I need to do it as less as possible. ...
1
vote
0answers
38 views

Service Connector abstraction for Ruby

My Rails apps need to connect to several external services to perform some functions. Now, I realize that some of the services I need might also be reused outside Rails (like in Capistrano ...
2
votes
0answers
360 views

Scoping through embedded document in MongoId

I'm using MongoId in a Rails project. I need to select some products which contain some SKUs which has an embedded document. The models are respectively Product and ...
2
votes
0answers
48 views

MySQL Workbench RoR Migration Exporter

I created plugin for MySQL Workbench that allows you to export an ER Diagram to RoR migration files. I would like to know if any other developers appreciate it. export-rails-4-migrations_grt.py <...
1
vote
1answer
49 views

Skip invalid record and avoid execution break for invalid record

Here is the pseudo code used inside a Rails controller: ...
1
vote
1answer
682 views

Directed Acyclic graph implementation in Ruby on Rails

I have an implementation for a graph node class that I'd like to have function as a directed acyclic graph. The associations are roughly as follows ...
1
vote
0answers
936 views

Converting ActiveRecord array to JSON

I have two tables, devices and device_properties. The devices table columns are as follows: ...
1
vote
2answers
4k views

Set ENV variables for Ruby on Rails

I've followed the steps from this video from railscasts for setting ENV variables. This is my configuration: config/database.yml ...
3
votes
1answer
67 views

Price rating approach

I'm pretty new to web development and I don't know if my solution is OK according to the best practices, considering performance and clean code. I have a Merchant model that belongs to a Price model. ...
1
vote
0answers
52 views

Rails JS event system

I'm working on a gem which is relatively simple. It works by adding data-controller and data-action attributes to the body tag ...
3
votes
1answer
864 views

Rails form helper to display email fields and their validation errors

I have a repeated pattern throughout my app that looks like this: ...
2
votes
1answer
49 views

Where should I put code which calculates stats which will be sent via mail

I want to send mail which will have day to day report. I have setup action mailer like this ...
-5
votes
1answer
47 views

Getting last 5 leave requests for a user - where does the code live [closed]

I have a User model, a user has_many leave_requests, in the user model I have the following code to find the last 5 leave requests: ...
5
votes
1answer
241 views

ActiveAdmin: Hide a whole panel in a smart way

In order to only show relevant information to my users I want to disable the whole panel when all fields inside that panel are empty. Currently I do this hacky method to get to this result: ...
1
vote
2answers
1k views

Finding mongodb records in batches using mongoid [closed]

I want to get records in batches. But mongoid doc says to avoid using skip due as it can be expensive. I wrote this method to iterate through a large number records efficiently. ...
3
votes
1answer
165 views

Imported data from CSV successfully, but slow

Currently I am using the gem activerecord-import to seed more than 55,000 records into my database, and it works fine. However, it takes too much time. I am ...
4
votes
3answers
1k views

Loop through months (1-12)

I currently have this monstrosity: next_period = (((current_month + tax_period_months)-1) % 12) + 1 I want to get the month that is ...
3
votes
1answer
64 views

List enrolled users & show checkmark if all activities are complete

I'm a beginner with rails working on a rails 4 project to use with my students. Users enroll in lessons; on enrollment, four activities are created for each user (expositions, scrambled, dictations, ...
-1
votes
1answer
808 views

ruby rails 4 initialize and increment instance variables

I have been tinkering with various ways to clean this up and I was wondering if it is more ideal to break this into small methods or way to accomplish this on a single line? ...
3
votes
2answers
3k views

Simple ActiveRecord attributes encryption in Rails 5+

The task at hand was to ensure that certain columns in the database are encrypted in case the database data is stolen. I have a feeling that a lot can be improved here (naming, DSL, encapsulations) ...
2
votes
2answers
109 views

Remove a key from list of hashes

Suppose my milestone is this: milestones = [ {state: 'unavailable'}, {state: 'arrived'}, {state: 'completed'} ] I want to remove all the ...
6
votes
2answers
739 views

Parsing Day Range with Time in Ruby

I need to shorten/simplify this code: ...
-1
votes
1answer
90 views

Rails - Events fully booked [closed]

I'm building an events app using Rails. I've installed a code block in my controller to ensure that over-booking doesn't occur once the total number of spaces for the event have been allocated/booked. ...
-1
votes
2answers
56 views

Refactor to avoid cope repetition in loop with condition checking

I have snippet that really look ugly but I don't know how to refactor it: ...
3
votes
2answers
375 views

Ruby Select uniq in one statement

I'm trying to implement some simple logic using rails. Code is working fine but its look uglier to me, could any one help me on refractor or implement in a efficient way. Context: Data hash ...
1
vote
1answer
22 views

Creating and sending two kinds of notification messages

I wish to get rid of using switch case with statuses twice in my code. But create_message function will be bigger in the future, so must stay and I don't want to ...
5
votes
3answers
75 views

Marking loans as paid if the payments exceed the loan amount

I have a Rails app where Loan has paid attribute. Loan should be marked as paid if total sum of payments is equal or higher than loan amount_to_pay. Problem is that ...
1
vote
1answer
55 views

Rails query for all questions in tournaments that a user participates in

I'm new to rails and this is the situation I'm in: I have a User model that has many tournaments, a Tournament has many users ...
3
votes
1answer
71 views

Rails UserHelper method

I need help cleaning up this monstrosity. Basically this is a user helper method that generates an array of cumulative user sign ups per week (start of week == Wednesday) starting 2016-06-15. So ...

1 2
3
4 5
12