Tagged Questions

Ruby on Rails is an open-source web framework that's optimized for programmer happiness and sustainable productivity. It lets you write beautiful code by favouring convention over configuration. Ruby on Rails website Riding Rails official blog API documentation Collaborative API documentation ...

learn more… | top users | synonyms

1
vote
1answer
18 views

Refactoring Query Rails 3 Active Record Fetch associated model based on conditions

Here is what I have. A User model and an Address model. User has_many :addresses and Adddress belongs_to :user. Now I want to search for users whose email contains a give term, or one of the users's ...
1
vote
2answers
55 views

Rails: “somefile.html.erb” -How can I make this code more concise and elegant?

Hi Im letting the users upload an file from the browser into my rails app. using paperclip gem. Once the file is uploaded it gets saved into the filesystem. When the user then goes in and the "show" ...
0
votes
1answer
28 views

Rails stylistic exception and bang usage

Question whether I should be throwing exceptions in the below model code (and rescuing in the controller - rescues not implemented below) or returning nil (in both or one of the exception cases). ...
1
vote
3answers
71 views

Refactor this Ruby on Rails code

Im wondering how could I refactor this code. It may look a little reiterative and probably there's a shorter method to accomplish the same. def self.location(distance=100,location) if ...
2
votes
2answers
116 views

Avoiding nested if statements

I occasionally find myself bumping into code like this (either in other projects or banging out initial prototypes myself): if @product.save if current_member.role == "admin" redirect_to ...
0
votes
0answers
20 views

Rspec Request always break when teammate push some changes, how to improve?

This is my rspec integration test for user , it always break when my teammate change something , how do i improve this? describe "Users" do before(:each) do populate_role end describe ...
0
votes
1answer
16 views

Should I create a category table or category field

create_table "announcements", :force => true do |t| t.string "title" t.string "category" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false ...
2
votes
0answers
108 views

Refactoring contest: Rails accepts_nested_attributes_for a many-to-many associated model

I found myself struggling when it came to refactor the following (working) code. Since can't be found a lot of documentation about Rails 'accepts_nested_attributes_for' applied to a many-to-many ...
2
votes
2answers
86 views

Controller code with exception handling

I am writing this code in the controller. I want to know is this the right way to write it or not. Because I don't want to write If else conditions and then either redirect or render the pages. Here ...
2
votes
1answer
47 views

Creating MarkDown documents in ruby

I'm trying to dynamically generate some MarkDown formatted documents, with header fields of arbitrary lengths. I want to have a title of arbitrary length underlined like this ...
0
votes
0answers
20 views

refactoring date and time columns convertion to Time(WithZone)

I got 2 colums representing a date and a time. {dateproc: '2012-03-23', horproc: '2000-01-01 16:15:23 UTC'} Both are read as a TimeWithZone by rails. I need to combine them. This is what I've ...
0
votes
1answer
54 views

activerecord, refactoring the source code

I have three tables class User < AR::Base has_many :lexemes, :dependent => :destroy end class Lexeme < AR::Base belongs_to :user belongs_to :word end class Word < AR::Base ...
1
vote
1answer
41 views

Select records and fill hash

I use ruby 1.8.7. I have method wich select records and fill hash. In my opinion the code is not dry. Could somebody help me to refactor it and make it shorter and more elegant? def fill_attributes() ...
1
vote
0answers
64 views

Nested Resources [closed]

I was reading rails guides on nested resources and they have the following: resources :magazines do resources :ads end A path of particular interest to me was: /magazines/:id/ads/:id ... the ...
1
vote
1answer
117 views

Tidying scaffolded Rails controller spec with subject/let

I was just looking at a standard scaffolded Rails controller spec, and tried to get it to use subject or let blocks, and failed miserably ... can subject or let tidy controller specs the same as it ...

1 2 3 4 5
15 30 50 per page