New to this environment and working my way through “Agile Web
Development with Rails”. I had a problem with decimal fields and am
using Edge Rails now to get around that issue - only I am now
experiencing other problems…
If you have this book, the exercise is Iteration A4: Prettier Listings
I have generated some ruby script with the command: ruby script/generate
scaffold product admin
The script produced is as follows:
class AdminController < ApplicationController
def index
list
render :action => ‘list’
end
GETs should be safe (see
URIs, Addressability, and the use of HTTP GET and POST)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }
def list
@product_pages, @products = paginate :products, :per_page => 10
end
def show
@product = Product.find(params[:id])
end
def new
@product = Product.new
end
def create
@product = Product.new(params[:product])
if @product.save
flash[:notice] = ‘Product was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end
def edit
@product = Product.find(params[:id])
end
def update
@product = Product.find(params[:id])
if @product.update_attributes(params[:product])
flash[:notice] = ‘Product was successfully updated.’
redirect_to :action => ‘show’, :id => @product
else
render :action => ‘edit’
end
end
def destroy
Product.find(params[:id]).destroy
redirect_to :action => ‘list’
end
end
When this script is called (http://localhost:3000/admin the following
error is generated:
app/models/product.rb:11: parse error, unexpected $, expecting kEND
RAILS_ROOT: script/…/config/…
Application Trace | Framework Trace | Full Trace
vendor/rails/activesupport/lib/active_support/dependencies.rb:204:in
load_without_new_constant_marking' vendor/rails/activesupport/lib/active_support/dependencies.rb:204:in
load_file’
vendor/rails/activesupport/lib/active_support/dependencies.rb:343:in
new_constants_in' vendor/rails/activesupport/lib/active_support/dependencies.rb:203:in
load_file’
vendor/rails/activesupport/lib/active_support/dependencies.rb:95:in
require_or_load' vendor/rails/activesupport/lib/active_support/dependencies.rb:249:in
load_missing_constant’
vendor/rails/activesupport/lib/active_support/dependencies.rb:453:in
const_missing' vendor/rails/activesupport/lib/active_support/dependencies.rb:465:in
const_missing’
vendor/rails/activesupport/lib/active_support/inflector.rb:162:in
constantize' vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb:148:in
constantize’
vendor/rails/actionpack/lib/action_controller/pagination.rb:195:in
paginator_and_collection_for' vendor/rails/actionpack/lib/action_controller/pagination.rb:130:in
paginate’
app/controllers/admin_controller.rb:12:in list' app/controllers/admin_controller.rb:3:in
index’
vendor/rails/actionpack/lib/action_controller/base.rb:1092:in
perform_action_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:632:in
call_filter’
vendor/rails/actionpack/lib/action_controller/filters.rb:634:in
call_filter' vendor/rails/actionpack/lib/action_controller/filters.rb:619:in
perform_action_without_benchmark’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in
perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in
measure’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in
perform_action_without_rescue' vendor/rails/actionpack/lib/action_controller/rescue.rb:115:in
perform_action’
vendor/rails/actionpack/lib/action_controller/base.rb:427:in
process_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:624:in
process_without_session_management_support’
vendor/rails/actionpack/lib/action_controller/session_management.rb:114:in
process' vendor/rails/actionpack/lib/action_controller/base.rb:330:in
process’
vendor/rails/railties/lib/dispatcher.rb:39:in dispatch' vendor/rails/railties/lib/webrick_server.rb:112:in
handle_dispatch’
vendor/rails/railties/lib/webrick_server.rb:78:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in
service’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in
start_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in
start’
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in
start’
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in start' vendor/rails/railties/lib/webrick_server.rb:62:in
dispatch’
vendor/rails/railties/lib/commands/servers/webrick.rb:59
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
require' vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in
require’
vendor/rails/activesupport/lib/active_support/dependencies.rb:343:in
new_constants_in' vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in
require’
vendor/rails/railties/lib/commands/server.rb:39
script/server:3
The error apparently means a missing “end” but i cannot see where…
Any clues?