ruby-on-rails

Summarise text

If I have some text that I want to print out on a page, but only want to print say the first 100 words before eclipsing it... what's the easiest way to do this? ...

Timestamps look different

In Rails, I find that timestamps in the console look different to the actual html view even when you have the same code. Unless I'm doing something really stupid: >> article = News.first => #<News id: 1, title: "Testing", body: "yadda yadda", role_id: 1, created_at: "2009-04-12 05:33:07", updated_at: "2009-04-12 05:33:07"> >> article.cr...

Web Service using Rails + MySql Best Practices

Alright, I need some advice and best practices from some Rails people. I'm fairly new to the platform but I've done database-backed web development work before in Java. At this point I've worked through about twenty tutorials, and I keep getting obstructed at the same place. Here's what I've done and what I'm experiencing. I've created...

Why do I get a 404 error when I try to access my rails site using https?

My server is currently hosting a php site. This site uses ssl for certain pages already. Now I am transitioning over to rails, and all my new rails apps go into a subfolder. Passenger is setup and and my app works great. One problem, If i try to go to these pages using ssl, I get a 404 error. Apparently apache is looking for the literal ...

What is the proper "Rails Way" to consume a RESTful web service on another domain?

I would like to write a Ruby on Rails application that consumes a RESTful web service API performs some logic on the result and then displays that data on my view. For example, let's say I wanted to write a program that did a search on search.twitter.com. Using pure ruby I might create the following method: def run(search_term='', las...

Testing models with multiple database connections in Rails using ActiveRecord

What is the best way to test a model that is using a different database connection in Rails. For example I have a model FooBar that is read only: class FooBar < ActiveRecord::Base establish_connection configurations['foo_bars'] # ... end Are there any good conventions, hacks, or plugins out there? ...

Can I destroy my /test folder if i'm using Rspec and Cucumber?

Is this possible? Or would I miss something? (Fixtures,..?) Because: When I use autotest with rspec, autotest doesnt seem to work? It loads, but nothing else happens, even if i change a file..? ...

With Rails, How can I expire the Browser's cache?

I have an issue with my Rails application and the browser's cache: When a user logs out of the authenticated section of the site, they are still able to use the back button on the browser to see the authenticated page. I do not want to allow this. How can I expire the cache and force it to reload. Thank you ...

Scrolling down a page after rendering in Rails

Is there a way to scroll or jump down a page after rendering it? Specifically, in my controller action, there are some situations where I'll want to send the user to a particular place on the page. If it were just a link from another page, I'd probably use a URI fragment identifier - "http://blorg.com/page#id" - but this needs to be dy...

How do you change your Rails App Data?

I have seen a lot of talk regarding ActiveRecord Migrations and whether or not they should be used to change data within your application, some people saying yes some saying no. My question is if you are not using Migrations to do this then what are you using? Just another script that you write? I am after suggestitions on alternative w...

Altering the primary key in Rails to be a string

So I've got two models, State and Acquisition. State has_many Acquisitions. I felt like an autoincrementing integer primary key for 51 records was rather silly. So I altered the model for the State to be the PK (State being the two letter abbreviation; I'm not storing the actual state name anywhere: class State < ActiveRecord::Base ...

How much code in a rails view is ok?

I know that it is best to keep code out of the presentation layer. But, I am wondering how much is considered "acceptable". For example I populate an html select box with this line of code. CodesecureProject.find(:all,:order => 'name').collect {|project| [project.name, project.id] } Right now I have this line of code embedded in th...

Direct "puts" in Rails, to Apache log

Hi, What's the configuration setting to get calls to puts to be written to the Apache log file? (Using Passenger to run Rails on Apache) Thanks ...

Techniques for storing/retrieving historical data in Rails.

Hello, I'm looking for some ideas about saving a snapshot of some (different) records at the time of an event, for example user getting a document from my application, so that this document can be regenerated later. What strategies do you reccomend? Should I use the same table as the table with current values or use a historical table? ...

Persisting memcache sessions in rails

Is it possible to use two session types simultaneously in Rails? Memcached for speed on reads and say SQL for persistence? I hate the idea of losing all sessions on reboots. MemcacheDB as mentioned below looks promising, but the idea would be to make all writes to disk, and all reads come from memory if possible. ...

Why aren't rails helpers more object-oriented?

For example, why are the date helpers written like this: time_ago_in_words(@from_time) Instead of like this: @from_time.time_ago_in_words Is this a clear design error / inconsistency? Or is there some reason for this? ...

Best Way to Test Rails REST XML API?

I want to test the REST api on my Rails site. What is the easiest/best way to do this with the rails testing framework? I'm only doing the standard resourceful stuff, so I am wondering in particular, since this is so bog standard, if there is any automagical way to test this stuff. ...

validates_associated and validates_presence_of not working as expected with rspec?

Hello, I have a User model and a Friendship-Model. class Friendship < ActiveRecord::Base belongs_to :sender, :class_name=>'User', :foreign_key=>'sender_id' belongs_to :receiver, :class_name=>'User', :foreign_key=>'receiver_id' validates_presence_of :receiver_id, :sender_id validates_associated :receiver, :sender end class Use...

RoR on GAE?

Since Google App Engine will soon full support Java: Would it be possible to run Ruby on Rails on Google App Engine? Or the limitations imposed by the AppEngine runtime will affect the JRuby implementation? What about other languages such as Groovy, Clojure, Scheme? Are there any effort to support .net and C# in JVM?? I think this wo...

how to parse multivalued field from URL query in Rails

I have a URL of form http://www.example.com?foo=one&amp;foo=two I want to get an array of values ['one', 'two'] for foo, but params[:foo] only returns the first value. I know that if I used foo[] instead of foo in the URL, then params[:foo] would give me the desired array. However, I want to avoid changing the structure of the URL if ...