ruby-on-rails

Cannot save text with double quotes in Rails ActiveRecord

I have this text. . . "I got them from the Wicked Witch of the East, when my house fell on her and killed her," she replied. "Where did you get the mark upon your forehead?" continued the voice. "That is where the Good Witch of the North kissed me when she bade me good-bye and sent me to you," said the girl. Again the ...

Assigning a nested attribute with Formtastic

I've been trying to figure this one out for a while but still no luck. I have a company_relationships table that joins Companies and People, storing an extra field to describe the nature of the relationship called 'corp_credit_id'. I can get the forms working fine to add company_relationships for a Person, but I can't seem to figure out ...

Rails 3 - Creating a JSON response to display Search Results

Hello, I'm working to have Rails 3 respond with a JSON request which will then let the app output the search results with the jQuery template plugin... For the plugin to work, it needs this type of structure: [ { title: "The Red Violin", url: "/adadad/123/ads", desc: "blah yada" }, { title: "Eyes Wide Shut", url: "/adadad/123/ads", d...

Is after_validation hook called every time on Active Record?

Is after_validation hook called every time, even when the validation is failed? I tried a couple tests and it seems like it! ...

How can I create a time-series bar graph in Ruby on Rails with a hash?

I am able to create a time-series "hash" using the statistics gem: => #<OrderedHash {"2010-10-23"=>2, "2010-09-22"=>3, "2010-09-11"=>1, "2010-08-27"=>1, "2010-10-15"=> 1, "2010-09-15"=>1, "2010-08-08"=>2, "2010-10-17"=>14, "2010-10-06"=>2, "2010-09-28"=>1, "2010-10-19 "=>1, "2010-09-20"=>1}> I want to create a simple graph with this d...

Is AuthenticatedSystem an open source RoR module?

I am looking at this github app, and they have a module named AuthenticatedSystem. I googled and found a rdoc, but can't find the source code for the module. Anyone heard of this? I know there are other authentication modules out there, but I am looking to just learn from this one as it looks simple to me. ...

This is my OAuth and TripIt controller. Is this sane?

I am working on integrating the TripIt API into a project of mine. I'm new to OAuth so I'm learning this as I go. The following controller seems to be working. However, I want to make sure I'm not leaving any glaring security holes or just being stupid. What do you guys/gals think? If anyone had a better example, I would certainly s...

Seed data for an American English dictionary.

I want to find seed data to load into my dictionary. I just need the word's orthographic representation (letters) and the definition. I'm looking for a single text file that contains this information to parse and then load into my db. I'm using rails so if there is a gem or plugin that can do this that would be nice if any knows about ...

Steps to create my own authentication system, need some guidance

I want to learn how to create my own authentication system, please provide some guidance if am doing this wrong. I will create a Module in my /lib folder /lib/auth.rb I will require this module in my ApplicationController. when a user enters their email + password, I will call a method that will do a lookup in the user's table for a u...

Paperclip attachments with dynamic style sizes from Model

Using Rails 2, I try to separate different, dynamic image sizes trough another Model from the Paperclip-Model. My current approach, using a Proc, looks the following: class File < ActiveRecord::Base has_many :sizes, :class_name => "FileSize" has_attached_file( :attachment, :styles => Proc.new { |instance| instance.attachment...

Issues with using subdomains with Cucumber/Capybara

I have successfully added the ability to use dynamic subdomains within my application. The issue is that when I run my Cucumber tests, I receive the following error when my application performs a redirect_to which contains a subdomain: features/step_definitions/web_steps.rb:27 the scheme http does not accept registry part: test_url.exam...

Does Capybara require JRuby?

I'm building a Rails 3 app. I'm trying to learn Cucumber with Capybara. Do I need JRuby to run Capybara via Cucumber? I've used Webrat, but many people seem to be using Capybara, so I'd love to try. I don't need JavaScript testing right away, but I want to install Capybara if I need in the end. I read and read the Capybara document...

How to mock request object for rspec helper tests?

I've a view helper method which generates a url by looking at request.domain and request.port_string. module ApplicationHelper def root_with_subdomain(subdomain) subdomain += "." unless subdomain.empty? [subdomain, request.domain, request.port_string].join end end I would like to...

Rails: How can I edit text files stored on Amazon S3?

I'm using paperclip to upload some text/csv files to an S3 bucket. I need to edit those files occasionally. How can I edit and re-save those? Before using S3, I was just using File.open for saving the files, but that throws a "No such file or directory" error now. ...

Rspec Test Error

Ruby 1.9.2, RoR 3.0.1. When I run 'rspec spec' I get this error. Can't really make sense of it. connor@connor-desktop:~/rubystore$ rspec spec /usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing': uninitialized constant Admins (NameError) from /usr/local/lib/ruby/gems/1.9.1/...

fakefs + paperclip on rails3 + rspec2 will give me an error "cannot generate tempfile"

rails (3.0.1) fakefs (0.2.1) paperclip (2.3.4) rspec (2.0.1) I am testing my model with rspec. Since this is a test, I want to prevent any file creations under the public directory as paperclip normally does. I am thinking this workaround is to use fakefs. Although I implemented this http://trevorturk.com/2008/12/11/easy-upload-via-u...

The unicode character from a rails app appears as ??? in the mysql databasse ,

The unicode character from a rails app appears as ??? in the mysql databasse (ie when I view through putty or linux console), but my rails app reads it properly and shows as intended.I have another java application which reads from the rails database and stores the values in its own database. and try to show in from its database. But in ...

Rails 3 - Truncate in a Controller?

Hello, in my controller I'm building a json object for books. I want to show truncate(book.content, 250) but that doesn't work in a rails controller? And given it's a JSON render, I don't use a view. So how does one truncate? I don't want my JSON object to be huge :)! thanks ...

Rails 3 uses HTML5 features. Do I need to do something for older browsers?

Many people still use IE 6 and other lower version browser. HTML5 is new, many browsers don't fully support it. If I want to use Rails 3, do I need to do some extra work? ...

Validating image dimensions in attachment fu

When the image gets saved, the height and width of the image get saved in the model correctly. I have a requirement where I need to validate the dimensions of the image before save. It has to be of precisely the same dimensions. But when I try to access height or width before save, it gives me nil. Is there any way where I can achieve t...