ruby-on-rails

localhost on rails

hi, I am sending an email that contains a link to my website. I want to be able to test it locally and be able to move the scripts around to different hosts easily. In my email right now I use the following: <%= url_for(:host => 'localhost:3000', :controller => "user_activations", :action => "show", :id=>@id, :confirm=>@passcode) %> ...

Delete everything from all tables (in Activerecord)

So I can do Post.delete_all to delete all my posts, but what if I want to delete all posts, comments, blogs, etc. I.e., how do I iterate over all my models and run the delete_all method? ...

Correct datatype for latitude and longitude? (in activerecord)

Should I store latitude and longitude as strings or floats (or something else)? (I'm using activerecord / ruby on rails, if that matters). ...

How can I migrate my database with rails to the first revision without dropping the database first?

I have a database set up for my Rails installation and some migrations set up. I would like to be able to reset my database back down to having no tables/constraints/etc., but can't find a reasonable way to do this without knowing the number of migrations or the timestamp of the first migration. Here are my options as I see them: rake ...

Rails ActiveRecord BigNum to JSON

Hi, I am serializing an ActiveRecord model in rails 2.3.2 to_json and have noticed that BigNum values are serialized to JSON without quotes, however, javascript uses 64 bits to represent large numbers and only ~52(?) of those bits are available for the integer part, the rest are for the exponent. So my 17 digit numbers become rounded o...

Immutable Active Record Relationships and Attributes (Setters)

I set out to solve a problem we have, where under certain circumstances; we may need to make an attribute or relationship immutable, that is once the attribute is written it is written forever. attr_readonly wasn't appropriate, as that didn't work for relationships, so I tried to prove the concept here: http://pastie.org/562329 This sh...

Natural language dates in ruby/rails?

I need to show natural dates like "few seconds ago" "21 minutes ago" Is there something built in to the rails? Or may be third party? This is not hard to implement, but I do not want to invent the wheel. ...

Which Rails plugins should I be using?

Hi Stack Overflow, I learnt rails a couple of years ago out of interest, but now I'm coming back to it because I want to try and build a simple pay-to-advertise niche job site with a few bells and whistles. Many of the rails books I learnt from gave examples of how to build a shopping cart or user authentication system, but looking arou...

How best to "merge" two objects and their associations in rails?

Here's my situation: I have 2 person objects, person1 and person2, which were created from two different external data sources. I have a manual process that I use that has determined that person1 and person2 actually refer to the same person, so what I want to do is "merge" them into a single person, and remove the duplicate. I have ...

How to make my Google Maps overlays taller (in Rails)

I'm trying to put my friend's restaurant reviews on a map (see the prototype at http://eatrichly.heroku.com/). The idea is that when you click a marker, you should see the review of the restaurant. Unfortunately, the popup that appears when you click a marker occasionally isn't tall enough to accommodate the corresponding review. E.g.: ...

problem using sql instead of named scope in rails

I have a method "search" in my model, which depending upon the various parameters passed runs an sql query in which i am joining seven tables. but when i am using this method with another named scope then error is shown "undefined method call for array". but when instead of this search method if i use group of named scope then it works ...

Nested resource with Atom Feed Helper

I'm trying to use the Rails Atom Feed Helper to generate a feed for a nested resource. My view template (index.atom.builder) is: atom_feed(:schema_date => @favourites.first.created_at) do |feed| feed.title("Favourites for #{@user.login}") feed.updated(@favourites.first.created_at) @favourites.each do |favourite| feed.entry(...

testing REST with shoulda and factory_girl - destroy

Hi, i'm developing test for REST using shoulda and factory_girl. Code below context "on :delete to :destroy" do setup do @controller = NewsArticlesController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @news_article = Factory.create(:news_article) en...

Trusted sites with oauth

Hi, Is there any ability to mark site as trusted? For example - somebody have some sites - auth.site.com (as oauth provider) and s1.site.com, s2.site.com etc as consumers. Of course - owner would like to skip step "Do you agree to add site s1.site.com as trusted?", but for security reason would like to not mark other sites like othersite...

Ruby on Rails: current_page? problem when using actions

I'm now implementing navigation tabs for my Rails application. I would like to generate different CSS and html for current tab (add id="current" and do not link the title) - basic stuff. I found the function: current_page? but unfortunately it doesn't work in a way i would expect: When I call: current_page?(:controller => "bank_accoun...

Paperclip save attachment

Is there a better way to save some string as an attachment via Paperlip as making a tmp file, putting the string into it, opening it again and saving it as an attachment ? Like this : def save_string data tmp_file = "/some/path" File.open(tmp_file,'w') do |f| f.write(data) end File.open(tmp_file,'r') do |f| ...

How to integrate Crystal Reports with Ruby On Rails??

How to integrate these two great tools? ...

can't activate activesupport (>= 2.3.2, runtime), already activated activesupport-2.1.2. what does it mean?

Hi, while trying to start some old revision of an opensource rails project confronted with a cloudy error message: "can't activate activesupport (>= 2.3.2, runtime), already activated activesupport-2.1.2" What does it mean? Either versions of rails and activesupport are installed on my box. I'm confused... ...

Rails, validates_format_of - minimum 4 alphabetic characters

Hello, How do I validate a field - so that it contains at least 3 alphabetic characters. Valid: Something, Foobar 111. Invalid: ....... Best regards. Asbjørn Morell ...

RoR: What would be the best SEO structure, adding a blog feature?

Hello, I have migrated a old php/mysql site to ruby on rails, and had to keep the old link structure - not to break incoming links. The structure look like this: domain.com/artists/user1/seo-friendly-name-of-painting1 domain.com/artists/user1/seo-friendly-name-of-painting2 domain.com/artists/user1/seo-friendly-name-of-painting3 etc. ...