ruby-on-rails

How do I inject <br> into text entered through a textarea in rails?

I have a textarea form which takes a large block of text. In this text area, I do a carriage return to end the paragraph and another carriage return to separate the paragraphs. That text is in @contact_postalcard.message. However, I need to output into an HTML file. The HTML file has been loaded as a long string which contains 'Rep...

Rails: Email a pdf generated with prawn to an email sent by ActionMailer?

I have an ecommerce app. I'm using Prawn to generate pdf invoices of orders. I'm using a standard Prawn setup. In views/admin/orders, I have a file called show.pdf.prawn. When the seller is viewing an order in his admin section, he clicks a link that opens the pdf version of the orders/show view. This all works perfectly. Now, the ...

How to parse XML from Rails in Flex

I want to upload a file(photo) from Flex to Rails and then send a response back to the server in XML (contains photo URL and ID). I'm sending from my Rails server some XML as follows: render(:xml => {:id => @photo.id, :photoURL => @photo.URL, :thumbPhotoURL => @photo.thumbURL}) This is sent through Fi...

send json object with httparty

Hi there, I'm trying to implement the in App purchase from within my iPhone app. To verify the receipt I need to send a json object to the iTunes server. Im trying to do this with the httparty plugin: require 'httparty' class ItunesVerification include HTTParty base_uri 'https://sandbox.itunes.apple.com' default_params :output =...

cannot understand rails activerecord typecast reasons

consider that i have a migration as follows create_table :dummies do |t| t.decimal :the_dummy_number end i instantiate like the following dummy = Dummy.new dummy.the_dummy_number = "a string" puts dummy.the_dummy_number the output for the above is 0.0 how did this happen? since i assign a wrong value shouldn't it raise a...

ActiveRecord - replace model validation error with warning

Hi, I want to be able to replace a field error with a warning when saving/updating a model in rails. Basically I want to just write a wrapper around the validation methods that'll generate the error, save the model and perhaps be available in a warnings hash (which works just like the errors hash): class Person < ActiveRecord::Base #...

Calling javascript functions from view in Rails 3

I am new to Rails and I have a pretty simple problem with calling javascript functions from within a view. In Rails 2 I would do... = javascript_tag "name(arguments)" where the javascript function "name" was located in my application.js file. However, this does not appear to work in Rails 3? Or am I missing something? I have been sear...

What's the point of "for x in y" in Ruby?

I'm learning Ruby and RoR at the moment, and I came across this: <% for post in @posts %> in the Rails guide. I'd understood that the idiomatic way to do this in Ruby is with: <% @posts.each do |post| %> If there is a difference then what is it? And if there isn't a difference then wouldn't it be better for the Rails people to be p...

Turn off "updated_at" column in Rails

Hi, I have a simple "Log" model, that records the fact of calling controller's action. Entries of this "log" record are supposed to be created once and never altered. Also, I will have many of these records in the database. So, there is no need for "updated_at" column (don't need to waste the memory on HDD). How can I tell to Rails t...

Rails deployment

Hello, I am new to Rails. I have my rails application and now I want to deploy it. What do i need to deploy my rails application? Do i need an IAS server or Apache would do it all? I am very confused because I have never deployed any website before ...

Storing a directory structure in database

In my rails app a user can have a directory structure which has folders and files in sub-folders. Which is the best way to store such data ?? Also, which database offers best way to do so? ...

Why won't formtastic reflect attr_accessible in the model (Ruby on Rails)

Why won't rails reflect attr_accessible in my model? class User < ActiveRecord::Base acts_as_authentic attr_accessible :name, :email, :phone, :password, :password_confirmation ... When I use formtastic or outprints the model xml, both reveals all the model fields like admin:boolean, password-encrypted:string and so on. Rails 2...

simple text to image solution for rails

Before I start rolling my own using Rmagick I though i'd ask as this is probably a quite common use case. I have a few hundred email addresses which I would like to display to the user for each entry however I would like to avoid displaying the emails as plain text to avoid scraping, so I'm looking for some text-to-image solution. It ...

Rebase Rails migrations in a long running project

In which I mean "rebasing" in the dictionary, rather than git definition... I have a large, long running Rails project that has about 250 migrations, it's getting a touch unwieldy to manage all of these. That said, I do need a base from which to purge and rebuild my database when running tests. So the data contained in these is importa...

how to check if my array includes an object - rails

So i have an array of @horses = [] that i start filling with some random horses. How can i check if my @horses array includes a horse that is already included (exists) in it? I tried something like: @suggested_horses = [] @suggested_horses << Horse.find(:first,:offset=>rand(Horse.count)) while @suggested_horses.length < 8 hor...

Is there a clean way for an ActiveRecord model to declare that its rows expire?

We're adding an expires_at column to one of our models. Among other changes, we've got to track down everything with a belongs_to relationship to the model and add the condition that expires_at must be in the future. Is there a way to do this centrally, so that rather than modifying all the other models, we modify the one that expires?...

Cucumber | Blank page after sending an email

Consider the following example: Scenario: Create New Account (Everything cool) Given I am not authenticated for "wellesley" When I go to register for "wellesley" And I fill in "Name" with "bill" And I fill in "Email" with "[email protected]" And I fill in "Password" with "please" And I fill in "Password Confirmation" with "please" And I ...

Session overlap, 2 users logged in somehow the system sees them as one.

Hello guys, Rarely our system mixes logged in users and I can't figure out why. Here is the scenario: 2 users log in (A and B) normally each one has his own ID, at some point one of the users (A) takes the ID of the other user (B) and contribute to the website as if he is B. Technically that's what is going on: 1- 2 users logs in: ea...

Rails w/custom TCP data service

I'm building a Rails app that needs to connect to a custom TCP data service, which uses XML messages to exchange data. Functionally, this is not a problem, but I'm having trouble architecting it in a way that feels "clean". Brief overview: User logs in to the Rails app. At login, the credentials are validated with the data service an...

How can I get picasa to work with auto_html in rails?

Is there a way to get auto_html to work with picasa (image hoster)? Actually I need a filter for this...but I do not know how to write it :( Does anyone know any resources? Or a solution? thanks in advance cheers tabaluga ...