ruby-on-rails

TypeError (Can't convert nil into String) With Attachment_Fu

I'm handling file attachments in my Rails app with Attachment_fu, which provides a public_filename method to retrieve a file's URL. I'm using it on a model called Cover, so if I want to call the URL of an uploaded cover image, in a view I would do: <%= image_tag(@cover.public_filename) %> This works just fine when the user has the app...

Rails: How to test code in the lib/ directory?

I have a model which gets its data from a parser object. I'm thinking that the parser class should live in the lib/ directory (although I could be persuaded that it should live soewhere else). The question is: Where should my unit tests for the parser class be? And how do I ensure that they are run each time I run rake test? ...

How do I configure the hostname of a Rails app?

I'm working on a fairly traditional forgot password email - I want to email the user a password change token embedded in a link that they can click on in order to change their password. I'm emailing via the traditional ActionMailer. If I use a normal link_to tag <%= link_to "click here", :controller => foo, :action => 'bar', :token =>...

Is there a good argument for combining Flex and Rails?

Since Rails is already an effective Rich Internet Application framework because of the way it makes Ajax so easy, what is the argument for combining Rails with Flex and using Flex as the front end instead of HTML? A programmer friend of mine said he uses this combination because Flex is great for RIAs. My argument is that Rails is alread...

Thinking Sphinx - RuntimeError: Missing Attribute for Foreign Key ...

Trying to get along with Sphinx/Thinking Sphinx for the first time. I've got my models defined as follows (simplified): class Branch < ActiveRecord::Base has_many :salesmen, :class_name => "User" has_many :leads, :through => :salesmen end class User < ActiveRecord::Base belongs_to :branch has_many :leads, :foreign_key => "ow...

Ruby daemon hangs on rails load

I am having issues getting a workling daemon working correctly. When I run: ruby script/workling_client run the daemon starts to load rails, but hangs indefintely. When I kill the process, the stack trace is always the same: /Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/core_ext/load_error.rb:32:in `new': Interr...

What's the point of freezing your Rails version/gems?

What does that mean? In the instructions for a project, it said to "freeze the Rails gems". Is that different from freezing the Rails version? What's freezing about? ...

How to display content that differs across controllers and methods in application layout?

I'm trying to display a javascript feedback widget in my default application.rhtml in a rails app. It will only appear on a subset of pages, distributed across different controllers. Trying to figure out the best way to do this. One thought was to do something like this: <%= render :partial => "layouts/feedback_tab" if @show_feedb...

(rails) taking from DB and rendering into HTML

Hi. I'm building a website for my Web Dev class, and I'm stuck on rendering HTML. I want to be able to use a simple form (Pretty much all I have right now is a scaffold for this controller, and I attempted sticking a content_type into my controller, but no progress.) to submit text and have it rendered as HTML. The idea is that, since th...

Keeping Tables Synced Across Rails Apps Without SQL replication?

I have a rails app that uses two of the same models as another rails app I have. What's the best way to keep data synced between two models? MySQL replication probably won't be possible due to hosting restrictions and since stuff that references the replicated data is dependent => :destroy meaning mysql replication will cause stuff tha...

Do I need to revert to an older version of Rails just to run a single legacy app (among other problems)?

I have an older Rails app that I need to run. But I have the latest version of Rails. When I try to run this older app it says: Missing the Rails 1.99.0 gem. Please gem install -v=1.99.0 rails But when I run the command: gem install -v=1.99.0 rails ERROR: could not find gem rails locally or in a repository Not sure what...

Ruby Time.parse gives me out of range error

I am using Time.parse to create a Time object from a string. For some reason Time.parse("05-14-2009 19:00") causes an argument our of range error, whereas Time.parse("05-07-2009 19:00") does not Any ideas? ...

simple RoR forum to integrate into my application?

Hi, Wanted to know if someone had a suggestion on code or maybe there's a plugin (!) which would allow very basic forum functionality that I can integrate into my application so that it is single sign-on? Otherwise...maybe a tutorial on how to build one from scratch and I just leverage our existing authentication? Thanks! I looked at...

successfully installed action_mailer_optional_tls to send using GMail?

Hi, I installed action_mailer_optional_tls for Rails 2.3.2 and Ruby 1.8.6 and I cannot get ActionMailer to send email! I get the following error: 530 5.7.0 Must issue a STARTTLS command first Sadness...anyone had success? ...

Clean way to find ActiveRecord objects by id in the order specified

I want to obtain an array of ActiveRecord objects given an array of ids. I assumed that Object.find([5,2,3]) Would return an array with object 5, object 2, then object 3 in that order, but instead I get an array ordered as object 2, object 3 and then object 5. The ActiveRecord Base find method API mentions that you shouldn't expect ...

How do I tell Rails that a string is an Acronym?

I have a field called sui in one of my models. It stands for "Standard User Identifier." When there are validation errors on the field, Rails prints "Sui is required" or "Sui is already taken." How can I tell Rails that 'sui'.titleize is "SUI"? I looked at Inflector.human, but that isn't quite right. ...

How should I present a cost field to the user, and store it in the database?

Right now I have two fields for cost. One for dollars and one for cents. This works, but it is a bit ugly. It also doesn't allow the user to enter the term "free" or "no cost" if they want. But if I only have one field, I might have to make my parser a bit smarter. What do you think? On the server side, I combine dollars and cents t...

Best practices for using AJAX without Rails' built-in helpers?

In my blog application, some posts appear as excerpts -- i.e., the user sees the first (say) 500 characters, and can click a link to view the entire post. Here is the relevant partial: <% href = url_for post_path(:id => post) %> <h1 class="title"><%= post.title %></h1> <h2 class="published_on"><%= post.author %> wrote this <%= time_ago...

When I have required model relationships, how do I guard against errors?

I have an application with a lot of database relationships that depend on each other to successfully operate the application. The hinge in the application is a model called the Schedule, but the schedule will pull Blocks, an Employee, a JobTitle, and an Assignment (in addition to that, every Block will pull an assignment from the databas...

ThinkingSphinx not accepting conditions

I'm having trouble getting ThinkingSphinx to recognize my conditions. My Discussion model includes the following code: define_index do indexes [subject, body], :as => :text indexes replies.body, :as => :reply_text set_property :delta => true end And as expected this search Discussion.search "handy" returns any discussion wit...