0

I have just started learning Ruby on Rails from pragmatic programmers 'Agile Web Development with Rails'.

I have wrote a small application and when it runs I receive the following syntax error when I run it:

/Users/colinlabri/Desktop/depot/app/models/product.rb:2: syntax error, unexpected ':',   expecting keyword_end
  attr_accessible : title, :description, :image_url, :price
                   ^
/Users/colinlabri/Desktop/depot/app/models/product.rb:2: syntax error, unexpected ',', expecting tCOLON2 or '[' or '.'
  attr_accessible : title, :description, :image_url, :price
                                        ^
 Rails.root: /Users/colinlabri/Desktop/depot

Application Trace | Framework Trace | Full Trace

app/controllers/products_controller.rb:1:in `<top (required)>'

The code for the DB is as follows:

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string : title
      t.text :description
      t.string :image_url
      t.decimal :price, precision: 8, scale: 2

      t.timestamps
    end
  end
end

Versions are as follow: ruby 1.9.3p362 Rails 3.2.11

Should I be checking my sqlite installation and how so?

2 Answers 2

1

You just need to fix this line:

t.string : title

to:

t.string :title

Your model also has the same problem in the attr_accessible call.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Marc, I should have known that! I have changed the above and saved the file now I get,Could not find table 'products'
Most likely your migration failed to run, or you haven't run it before. Try rake db:migrate from your terminal.
0

:something are actually symbols in Ruby. You cannot leave any space between : and the symbol name.

Change t.string : title to t.string :title in the migration file.

And in your product model,

Change attr_accessible : title to attr_accessible :title

1 Comment

Thank you, I now get Could not find table 'products'?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.