Controller changes format on variables when publishing

Posted by Christoffer on Stack Overflow See other posts from Stack Overflow or by Christoffer
Published on 2011-02-20T07:21:48Z Indexed on 2011/02/20 7:24 UTC
Read the original article Hit count: 248

Filed under:
|
|

I am a newbie to ROR but catching on quickly. I have been working on this problem for a couple of hours now and it seems like a bug. I does not make any sense.

I have a database with the following migration:

class CreateWebsites < ActiveRecord::Migration
  def self.up
    create_table :websites do |t|
      t.string :name
      t.integer :estimated_value
      t.string :webhost
      t.string :purpose
      t.string :description
      t.string :tagline
      t.string :url      
      t.integer :adsense
      t.integer :tradedoubler
      t.integer :affiliator
      t.integer :adsense_cpm
      t.boolean :released
      t.string :empire_type

      t.string :oldid
      t.string :old_outlink_policy
      t.string :old_inlink_policy
      t.string :old_priority
      t.string :old_profitability



      t.integer :priority_id
      t.integer :project_id
      t.integer :outlink_policy_id
      t.integer :inlink_policy_id

      t.timestamps
    end
  end

  def self.down
    drop_table :websites
  end
end

I have verified that what is created in the database also is integers, strings etc according to this migration.

I have not touched the controller after generating it through scaffold, i.e. it is the standard controller with show, index etc.

Now. When I enter data into the database, either through the web form, in rails console or directly in the database - such as www.domain.com for url or 500 for adsense - it will be created in the db without problem.

However, when it is being published on the website the variables go completely nuts. Adsense (integer) turns into date, url (string) turns into a float, and so on. This only happens to a few of the variables.

This will also create a problem with "argument out of range" since I input 500 and Rails will try to output it as date => crash and "argument out of range".

So, how do I fix/trouble shoot this? Why do the formats change? Could it be because of the respond_to in the controller?

Cheers,

Christoffer

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about format