1

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

Controller:

class WebsitesController < ApplicationController
  # GET /websites
  # GET /websites.xml
  def index
    @websites = Website.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @websites }
    end
  end

  # GET /websites/1
  # GET /websites/1.xml
  def show
    @website = Website.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @website }
    end
  end

  # GET /websites/new
  # GET /websites/new.xml
  def new
    @website = Website.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @website }
    end
  end

  # GET /websites/1/edit
  def edit
    @website = Website.find(params[:id])
  end

  # POST /websites
  # POST /websites.xml
  def create
    @website = Website.new(params[:website])

    respond_to do |format|
      if @website.save
        format.html { redirect_to(@website, :notice => 'Website was successfully created.') }
        format.xml  { render :xml => @website, :status => :created, :location => @website }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @website.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /websites/1
  # PUT /websites/1.xml
  def update
    @website = Website.find(params[:id])

    respond_to do |format|
      if @website.update_attributes(params[:website])
        format.html { redirect_to(@website, :notice => 'Website was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @website.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /websites/1
  # DELETE /websites/1.xml
  def destroy
    @website = Website.find(params[:id])
    @website.destroy

    respond_to do |format|
      format.html { redirect_to(websites_url) }
      format.xml  { head :ok }
    end
  end
end

View:

<h1>Listing websites</h1>

<table>
  <tr>
    <th>Name</th>
    <th>Estimated value</th>
    <th>Webhost</th>
    <th>Purpose</th>
    <th>Description</th>
    <th>Mail text</th>
    <th>Adsense last year</th>
    <th>Tradedoubler last year</th>
    <th>Affiliator last year</th>
    <th>Adsense cpm</th>
    <th>Tagline</th>
    <th>Url</th>
    <th>Released</th>
    <th>Empire type</th>
    <th>Priority</th>
    <th>Project</th>
    <th>Outlink policy</th>
    <th>Inlink policy</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @websites.each do |website| %>
  <tr>
    <td><%= website.name %></td>
    <td><%= website.estimated_value %></td>
    <td><%= website.webhost %></td>
    <td><%= website.purpose %></td>
    <td><%= website.description %></td>
    <td><%= website.adsense %></td>
    <td><%= website.tradedoubler %></td>
    <td><%= website.affiliator %></td>
    <td><%= website.adsense_cpm %></td>
    <td><%= website.tagline %></td>
    <td><%= website.url %></td>
    <td><%= website.released %></td>
    <td><%= website.empire_type %></td>
    <td><%= website.priority_id %></td>
    <td><%= website.project_id %></td>
    <td><%= website.outlink_policy_id %></td>
    <td><%= website.inlink_policy_id %></td>
    <td><%= link_to 'Show', website %></td>
    <td><%= link_to 'Edit', edit_website_path(website) %></td>
    <td><%= link_to 'Destroy', website, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'New Website', new_website_path %>

Output:

Name: Example.com

Estimated value: 1000

Webhost: Host.com

Purpose: Yada

Description: Yada yada

Adsense last year: 946684824

Tradedoubler last year: 0

Affiliator last year: 946684824

Adsense cpm:

Tagline:

Url: 0.0

Released: false

Empire type: 0

Priority:

Project:

Outlink policy:

Inlink policy: 

For this output I used the following input:

Name: Example.com
Estimated value: 1000
Webhost: Host.com
Purpose: Yada
Desc: Yada yada
Adsense last year: 0
Tradedoubler last year: 0
Affiliator last year: 0
...
The rest of the fields I left blank

Note, for example, that url was left blank (and created a 0.0 output). Empire type was left blank and created a 0 output.

To further clarify, the data in the database is EXACTLY as my input. It is only the output that is wrong.

When I go back to edit mode. The output (default value) for "Adsense" and "Affiliator" shows 2000-01-01 00:00:24 UTC.

  • What exactly do you mean by "publishing"/"published on the website"? – Andrew Marshall Feb 20 '11 at 07:26
  • When Rails takes the data from the database/application and makes it visible through my web browser. I.e. the data is ok in the db but gets messed up when being viewed through the application.I am running the website locally on my laptop with a mysql-database. – Christoffer Feb 20 '11 at 07:34
  • if you want any meaningful advice youd have to give us a glimpse into your controller, your view as well what output you're getting – Vlad Gurovich Feb 20 '11 at 08:12
  • Ok, I have edit the post with as much as I can. Hope you can help me with it! – Christoffer Feb 20 '11 at 09:48

1 Answers1

0

Your table headers don't match the cells. For example your 6th <th> is "Mail text", but the value displayed in the related <td> is website.adsense, and so on.

Adrian Pacala
  • 1,011
  • 1
  • 8
  • 12
  • That seems to be completely unrelated to the OP's question, no? – Manuel Meurer Feb 20 '11 at 10:01
  • 1
    That's the point. Values appear to be wrong because of the misplaced labels. – Adrian Pacala Feb 20 '11 at 10:17
  • Thanks, but that has nothing to do with it though. It seems it has to do with my local installation. A friend of mine tested it on his local server (laptop) and it worked alright. I reinstalled Wamp but still have the same problem. – Christoffer Feb 20 '11 at 11:08
  • It could also be noted that this problem occurs at several different views...not just this one. – Christoffer Feb 20 '11 at 11:30