1
vote
1answer
29 views

Seeking code review for registering or logging in when creating a new comment object

This service object allows users without a session to create a comment, and register OR login at the same time. If a user is signed out he must enter an email and a password along with the comment. ...
0
votes
1answer
128 views

Review my ruby for performance

So I'm using the acts_as_taggable_on gem to tag 3 different models: Question, Blog, and Video Each one has a site_id to distinguish which site they show up on (SaaS-ish). I wanted to get all tags ...
2
votes
0answers
41 views

Rails service + oauth code structure

I'm having trouble structuring the logic of OAuth integration into my web app. In the app, a user creates a Report that consists of data from their google analytics account. User steps: User clicks ...
1
vote
1answer
60 views

DRY up Rails Navigation Code

In my Rails 4 app i used to have every view contain a content_for :nav tag which included all of the links for the nav bar in my layout. This was getting annoying because if i wanted to add a button i ...
1
vote
1answer
37 views

Clean up Rails Routes

Is there any way I can DRY up this Rails 4 routes.rb code? match '/oauth/apps/' => 'oauth/applications#index', :as => :oauth_applications, :via => :get match '/oauth/apps/new/' => ...
0
votes
3answers
96 views

Tell me how to improve my code?

I am a redneck coder that I was not happy! How can I improve this code: def show if params[:type]=="all" if params[:dir] =="next" @work = Work.find(:first, :conditions => ["id > ? ...
1
vote
0answers
35 views

Dynamic Controller Creation in Rails

I have overrode Rails' ActionDispatch::Routing::RouteSet::Dispatcher.controller_reference method to check if a controller exists by checking for the required constants and then creating them based ...
2
votes
1answer
59 views

How do I refactor this ActiveRecord object to lessen dependency on callbacks?

I have an Order object that belongs_to a BillingAddress and a ShippingAddress. I want to present my user with only ShippingAddress fields and a checked checkbox indicating that the billing address ...
2
votes
1answer
75 views

Mapping arrays to ranges in Ruby

I have a simple Rails app, which is used to run some clinical surveys. Participants answer sets of questions (multiple-choice, valued 1-5), and, within each set, the answers are summed up and the ...
0
votes
1answer
72 views

Math Calculus in ruby

I have several calculus to do in my ruby app. My code is currently working but I find it very ugly. @guestreviews = GuestReview.where(:reviewed_id => @user.id) @hostreviews = ...
1
vote
1answer
86 views

Rails: Setting a transient attribute on a set of objects from one model based on information from a junction model

I have a user model, a task model, and a junction model user_task that saves the data joining the two: class Task < ActiveRecord::Base attr_accessor :completed_on has_many :user_tasks class ...
3
votes
1answer
136 views

Nasty Age Printing Method

I have this ugly age printing method. Can you do better? def age(birth_date) today = Date.today years = today.year - birth_date.year months = today.month - birth_date.month (months -1) if ...
1
vote
4answers
90 views

can this rails code be simplified and be more efficient? nested if else statements

Here's a part of my controller and it's getting quite lengthy (the code works). Would this code slow down the performance of my website? Can it be cleaned up and be written more efficiently? def ...
2
votes
3answers
74 views

I need help refactoring some Rails code that looks clunky.

I would like to refactor this block, it looks clunky: # refactor me receive_payment_on = false config[:sections].each do |section| if section[:applicants] section[:applicants][:sections].each ...
2
votes
1answer
54 views

two or more render/redirect in the same method

I often have method like this one with two or more render to do due to catching the error for example. I currently do something like this: def update @user = current_user if ...

1 2 3 4 5 6
15 30 50 per page