ruby-on-rails

Ruby syntax checking in vim

Hi everyone, I use vim with various plugins for editing ruby code. I have proper syntax highlighting set up but I was wondering if anyone knew of a way to get ruby syntax checking, similar to what you might see in an IDE such as visual studio, radrails, etc? Something that would simply turn stuff red or break highlighting when I'm m...

undefined method grouped_options_for_select

Anyone have any idea why the following code is resulting in an "undefined method 'grouped_options_for_select' for #<ActionView::Base:0x43881ec>" error? @user_options = [['Group 1',['User 1','User 2']],['Group 2',['User 3','User 4']]] select_tag('ufc[proponent]',grouped_options_for_select(@user_options)) I'm about to pull my hair out, ...

How can I send the multiple ids to controller in this view ?

Hi I want to send multiple ids that selected with checkboxes to the controller in this code : <% form_for :product do %> <table border="1px"> <tr> <th> Select </th> <th> Image </th> <th> Product Name </th> <th> Product Descripti...

Rails vs Ruby CGI

I have a boss who is convinced learning Rails is too steep a learning curve and not cost effective from a labor standpoint when straight Ruby running as a CGI app on Apache is available. He is proposing, for our rewrite, that we use straight Ruby w/ no framework rather than Rails (or Merb, Sinatra, etc.) I believe in my heart that this...

Force a save! operation to fail

I have an ImagesController that kicks off a non-trivial save operation. Here's the high-level background: I have several different physical file types to deal with in my application. Each of these belongs_to a Binary. Files can be created, of course, and this process involves uploading a physical file to a temporary location, possibly v...

"autotest/rails [...] doesn't [...] exist. Aborting"

I'm finding that autotest has stopped working... $ autotest loading autotest/rails Autotest style autotest/rails doesn't seem to exist. Aborting. According to this blog post, the common reason for this error is that people don't have the autotest-rails gem installed. However, I definitely have that installed: autotest-rails (4.1.0) Z...

Count value of records which belong to other model in rails.

Hey everyone, This is probably pretty basic, but I'm trying to figure out how to show how many comments a post has in rails, on the post index page of my app. comments belongs_to post, and post has_many comments Just not sure how to show on the index page, the amount of comments for each post. Thanks in advance! Elliot ...

How to model interpretations of rap music

I just started working on a website that will help people understand what rappers are talking about. Users will see the lyrics to a rap song and they'll be able to click certain lyrics to see an explanation. Here's a screenshot (you can also check out the site itself here): (Original lyrics censored; click here to see them) Anyway, m...

Overriding Rails mislav-will_paginate plugin

I'm working with the Rails mislav-will_paginate plugin to paginate my records. I want to produce the following output, regardless of whether there were multiple pages: X - Y of Z 1 - 100 of 1826 will_paginate in WillPaginate::ViewHelpers returns nil if there was only one page of records. I want to override this in the cleanest possibl...

Why is ActiveRecord not smart enough to know that the object_id of the father should be equal to the object_id of the parent of each of the father's children?

@father = Hierarchy.find(:first, :conditions => ['label = ?', 'father']) @father.children.each do |child| puts @father.object_id == child.parent.object_id end I would have thought the results here would be all true. Instead they are all false. Why does ActiveRecord work this way instead of recognizing that these are the ...

ActiveRecord::RecordNotFound -- Couldn't find User without an ID

Please see UPDATES at the bottom of the question... For reference, this problem evolved out of some fixes I made based on a previous problem I was having here: http://stackoverflow.com/questions/1298846/associating-two-models-in-rails-user-and-profile I'm building an app that has a user model and a profile model. I want to associate t...

Listing buckets with AWS::S3 in Sinatra

I'm trying to access my Amazon S3 account using the aws-s3 gem, but no matter what I do, I can't even print a bucket list. Error: undefined method `bytesize' for #<AWS::S3::Bucket:0x1b9e488> From Code: # hello_world.rb require 'rubygems' require 'sinatra' require 'aws/s3' get '/' do connection = AWS::S3::Base.establish_connection...

How do I speed up my Ruby application?

I am making a data intensive web application that I am trying to optimize. I've heard of forking and threading, but I have no idea whether they are applicable to what I am trying to do and if so how to implement them. My code looks like this: def search @amazon_data=Hash.from_xml(item.retrieve_amazon(params[:sku])) unles...

How do I get my look up table values in a select box?

Reading along with the agile book, it says this in a footnote: ... You simply pass the select helper the result of doing a find(:all) on your lookup table. Okay ... <%= f.select :source, Source.find(:all) %> My source controller (and therefore table) looks like this: create_table :sources do |t| t.string :source t.times...

How do I update a model object's associated object?

Hi, I want to something like the following: @user.update_attributes(:name => "Obama", :profile => { :current_location => 'US' }) where User has_one profile. ...

Form show/hide effect with Rail's prototype helpers

I'm trying to make a threaded comments system that behaves like Reddit's: I click "Reply" on a comment, a form shows up. This form has a "Cancel" button that removes the form, going back to the original state. I'm trying to achieve that with one link_to_function that adds the form, and the form itself has a button_to_function to remove ...

Validate that string belongs to specific language alphabet

How can I validate Rails model string attribute that it belongs to specific language alphabet characters? Thanks. ...

How to return the number of Posts Tagged with "example" using acts_as_taggable under ROR

How to return the number of Posts Tagged with "example" using acts_as_taggable under ROR currently I am implementing this by declare <%=Questions.find_tagged_with("example", :match_all => true).size%> I wonder if there is any other better solutions out there, thank you in advance! ...

Accessing model properties in Rails

So basically I have a controller. something like this def show @user = User.find[:params[id]] #code to show in a view end User has properties such as name, address, gender etc. How can I access these properties in the model? Can I overload the model accesser for name for example and replace it with my own value or concatenate someth...

Rails - how to avoid cross site scripting

how to avoid cross site scripting in "ruby on rails" i used the code below <%= link_to h(@user.name), user_url(@user) %> and, i want to know, how and where do we check this script is working or not. ...