Ruby script/generate scaffold Product Admin hangs


#1

Hi

I am running Mac OX tiger with the installed ruby 1.8.2, and
mysql5 (I checked that it was running in preference). I
tried to run the various fixes recommended in agileweb. I am
stuck on page 57, script/generate scaffold…

Could you paste in your database.yml file, from the
“config” folder inside your Rails app? If you have any
passwords entered there, you should change them to
nonsense before sending.

development:
adapter: mysql
database: depot_development
host: localhost
username: root
password: $564^%#

test:
adapter: mysql
database: depot_test
host: localhost
username: root
password: 0#@^463

production:
adapter: mysql
database: depot_production
host: localhost
username: prod
password: wibble

Is there a way to check that I have indeed all the pieces
fixed that need to be fixed? the #46 fix, or how do I test
this mysql gem?

thank you for your help,

anne


#2

I replaced the default list.rhtml with the copy/paste of the
text of page 67-68 from the rails-code.tgz and added the
text with copy/paste for page 69 scaffold.css.

I get an error message which starts with
compile error
script/…/config/…/app/views/admin/list.rhtml:1: syntax
error
_erbout = ‘’; _erbout.concat “

Product
Listing

\r\r<table cellpadding=“5”
cellspacing=“0”>\r”;
odd_or_even = 0
for product in @products
odd_or_even = 1 - odd_or_even
; _erbout.concat “\r <tr valign=“top” class=“ListLine”;
_erbout.concat(( odd_or_even ).to_s); _erbout.concat
“”>\r\r \r <img width=“60” height=“70”
src=”"; _erbout.concat(( product.image_url ).to_s);
_erbout.concat “”/>\r \r\r <td width=“60%”>\r
<span class=“ListTitle”>"; _erbout.concat((
h(product.title) ).to_s); _erbout.concat “
\r
“; _erbout.concat(( h(truncate(product.description, 80))
).to_s); _erbout.concat “\r \r\r <td
align=“right”>\r “; _erbout.concat((
product.date_available.strftime(”%y-%m-%d”) ).to_s);
_erbout.concat “
\r $”; _erbout.concat((
sprintf(”%0.2f”, product.price) ).to_s); _erbout.concat
"
\r \r\r <td class=“ListActions”>\r
"; _erbout.concat(( link_to ‘Show’, :action => ‘show’, :id
=> pro

As far as I can tell, the downloaded code from depot4 folder
is the same as in the book. How do I debug a syntax error
like this?

anne


#3

Without seeing the rhtml I can’t offer a definitive reason. When I get
syntax errors like this I usually back out whatever I have added to my
RHTML, and add it back incrementally to spot the error.

~ Ben


#4

Check that you haven’t put a <%= when you meant <%
That’s sometimes been the cause of similar errors for me.


#5

On 1/26/06, Anne G removed_email_address@domain.invalid wrote:

cellspacing=“0”>\r";
"; _erbout.concat(( h(truncate(product.description, 80))
is the same as in the book. How do I debug a syntax error
like this?

Can you paste in the code? Usually the “line 1” error means that
you’ve got a <% or <%= opening tag that isn’t closed. Unfortunately,
these “totally couldn’t handle it” error messages are the hardest to
track down. Luckily, they usually end up being something really
simple. You can find them with an editor that has serious syntax
highlighting (like vim or TextMate).
If you’re using something else, you can chop it up into pieces and run
it a bit at a time. Add one block of code at a time, until you find
the error.


#6

Of course, right after I posted this info, I realized that
there are two languages intermixed, the % language and the
table language. And the first few lines start a for loop
which is closed just before table is closed.

Once I understood that, I was able to modify the list file
little by little. It was cool to watch the changes happen.
The book does not bother explaining anything, so at least
with this method, you can guess what is going on, and look
it up if it is of interest.

I added the lines little by little, taking away lines also
until the list file was the same as far as I could tell as
the book’s file I was copying from, and no syntax error. —
the pictures did not load, oh well ~/Desktop/image.jpg —

I recopied the original text from the code download into
the list file, and the syntax error came back.

I will try again tomorrow. Thank you for your advice

anne


#7

this is the text copy pasted from the list.rhtml file from
the book’s rails-code.tgz from folder depot4: list.rhtml
should be as listed page 68.

text wrangler does put some colors, I did not see any
mismatch. I start geting an error as soon as I put the
first lines with <% … %> that seems to define some macro,
don’t know why it would triger an error.

Product Listing

<% odd_or_even = 0 for product in @products odd_or_even = 1 - odd_or_even %>
<td>
  <img width="60" height="70" src="<%= product.image_url

%>"/>

<td width="60%">
  <span class="ListTitle"><%= h(product.title)

%>

<%= h(truncate(product.description, 80)) %>

<td align="right">
  <%= product.date_available.strftime("%y-%m-%d")

%>

$<%= sprintf("%0.2f", product.price)
%>

<td class="ListActions">
  <%= link_to 'Show', :action => 'show', :id => product

%>

<%= link_to ‘Edit’, :action => ‘edit’, :id => product
%>

<%= link_to ‘Destroy’, { :action => ‘destroy’, :id =>
product },
:confirm => “Are you sure?” %>

<% end %>

<%= if @product_pages.current.previous
link_to(“Previous page”, { :page =>
@product_pages.current.previous })
end
%>

<%= if @product_pages.current.next
link_to(“Next page”, { :page =>
@product_pages.current.next })
end
%>


<%= link_to ‘New product’, :action => ‘new’ %>


#8

Hi Anne ~

Images need to be in the rails_root/public/images folder. It looks like
you
were trying to refer to your desktop.

~ Ben


#9

HI

Rails normally has an rhtml file on the server which is
interpreted. If the rhtml has a load image command,
it loads the image and presents it to the user.

Is there a way to have Rails load all the images that are
going to be used ahead of time? How would the code look
different?


usually the user clicks on submit, which is really a link
which is interpreted as a request by the controller.

Is there a way to have Rails respond to a key press
by storing the content of the key press and moving on to
load the next image


As I understand it, the timing is mostly controlled by the
user clicking on a link. Until then the server just sits
there waiting for someone to request a link

How can I use Ajax to control the timing of the presentation
independently of a link request?

thanks for your help

anne


#10

Loading pictures up front:

I found the following: “a plethora of solutions to the
preloading image problem in JavaScript are available.”
http://www.ilovejackdaniels.com/css/preloading-images-with-css/

So that is a problem that people are thinking about, and
there are ways to do it. I know that rails gives access to
javascript through helper functions, so I am wondering if
the ability to load pages all at once, or images all at once
is available in rails.

I hear that the Times has set it up so all the articles load
up at once, so reading the paper is very fast, the articles
are already there.


for key presses, it might be more difficult, people seem
more focused on the mouse, on mouse roll over… but if they
give mouse interactivity, they give keyboard interactivity.


It seems to me that as web application are taking over
behaviors of computer applications, they will need to do all
the things a computer application can do, but we may be at
the beginning of that era. Flash can do all I want to do,
and it is loaded into and runs from a browser, but other
tools like Rails may not be able to do such things yet?


I can always find my post on the web archive, but I don’t
usually find them in the gmane rails archive. Yet they are
mirrors of each other, no?

thanks for your help


#11

Very strange, this morning, the error was there. I went
backward, taking code out chunk by chunk, but some error was
there all the way. until I went to a blank page.

I restarted with the download file, and now I don’t get any
error. I can’t get the error even with the old files I
believe gave the error.

I tried editing the path of the image to image that are
already in the images folder in public,
image url
/images/sk_auto_small.jpg
/public/images/sk_auto_small.jpg

nothing works.


#12

feed://rss.gmane.org/gmane.comp.lang.ruby.rails

Javascript to preload images for faster loading on later
pages:

Use of the image Image-Name-1.gif in subsequent pages will
be loaded from chache.

that should do the trick, load all the images at the start.
But where do I put this javascript code in a rails project?

I want to keep track of a person with session, and keep
changing the picture as he proceeds with task…


#13

Anne G wrote:

is available in rails.

It’s available the same way it’s always been available - through
judicious use of the right bits of HTML, Javascript and CSS. There
aren’t many bits of Rails that specifically help browser pre-caching, or
hidden div loading, but then there’s nothing to get in the way either…

I hear that the Times has set it up so all the articles load
up at once, so reading the paper is very fast, the articles
are already there.
Not that I can see… Have you got a reference for that?

for key presses, it might be more difficult, people seem
more focused on the mouse, on mouse roll over… but if they
give mouse interactivity, they give keyboard interactivity.

Again, this is an HTML/Javascript thing, not Rails-specific. There
might be some functionality in RJS templates to help out, but I can’t
think of any off the top of my head. The accesskey attribute on form
elements and links might be enough to give you the keypress
functionality you want.

It seems to me that as web application are taking over
behaviors of computer applications, they will need to do all
the things a computer application can do, but we may be at
the beginning of that era. Flash can do all I want to do,
and it is loaded into and runs from a browser, but other
tools like Rails may not be able to do such things yet?
There’s nothing really technologically new Rails brings to the table.
It just ties everything together in a really tidy package.


#14

Anne G wrote:

Use of the image Image-Name-1.gif in subsequent pages will
be loaded from chache.

that should do the trick, load all the images at the start.
But where do I put this javascript code in a rails project?
Put that code in a template that will get loaded by the browser before
the images are needed. Maybe in the head of application.rhtml, if it’s
site-wide.


#15

Thank you Alex for your help on this

anne


#16

On another programming list on which I’m active, I’ve (of course)
mentioned my newfound interest in and focus on Rails. One of the long-
time members, a pretty thoughtful guy, has emailed me privately and
asked me if I could point him to any Rails apps that were handling
huge amounts of traffic. I’ve had the usual conversations with him
about what scalability really means, how few sites need to handle
huge amounts of traffic, how Rails is just one component of the
landscape, etc.

Still, he wants to know if I can point him to any large-scale apps
done in Rails. Is there an answer to this question? Or is it just one
of those diversionary issues raised by people who are looking for
some reason not to spend the time to evaluate a new technology deeply
enough to draw their own conclusions?

Thanks.

(I did look at http://wiki.rubyonrails.org/rails/pages/RealWorldUsage
but it’s impossible, of course, to tell which of those sites might be
handling huge traffic volumes.)


#17

A couple of the more well known applications would be 43 Things
(http://www.43things.com/) with somewhere between 500K and 1MM
requests per day and Basecamp (http://www.basecamphq.com/) with over
100,000 users. Others on the list can probably give you more
specific examples for these two applications as well as others.

Steven S.


#18

I have a database exp
in database.yml I have in the development section

adapter: mysql
database: exp
username: root
password: ***
host: localhost

That should allow for connection to the mysql database exp.

I created a table stimulis, with 45 records of
three columns
id image_url name
select * from stimulis shows them all in mysql

  1. I generated a model file stimuli.rb

class Stimuli < ActiveRecord::Base
end

this somehow establishes the connection with the table
stimulis

  1. I have a controller and an action hello

class RunexpController < ApplicationController
def hello
@stimuliAr = Stimuli.find_all
end
end

  1. I have a viewing html
<% @stimuliAr.each do |stim| %> <%= link_to stim.image_url, :action => "show", :id => stim.id %> <% end %>

I don’t have a show page yet, but that should not be a
problem.

when I try to view
http://localhost:3000/runexp/hello
in railrad

I get an error message
access denied for user ‘root’@‘localhost’ (using password
no)
which is strange because mysql is setup with a password, and
I gave it in the config file, database.yml.

I am probably missing a piece which is normally setup by
scafold, is that so? what do I need to do?

Am I on the right track?

thanks

Anne


#19
  1. I put a space in front of the password in database.yml,
    after “password:”
  2. I rebooted the computer.

It now seems to work. I am able to access all the
information.

How can I generalise to several tables. I assume I
need one model per table?

How do I write to a table?

What do I need to understand about relational tables?

thanks for a little help, this is good learning, but it is
so slow finding this info, most tutorials I looked at use
scaffold

anne


  1. I generated a model file stimuli.rb

class Stimuli < ActiveRecord::Base
end

  1. I have a controller and an action hello

class RunexpController < ApplicationController
def hello
@stimuliAr = Stimuli.find_all
end
end

  1. I have a viewing html
<%= link_to @stimuliAr[0].image_url, :action => "show", :id => @stimuliAr[0].id %>

#20

Hey Dan !

I really dig this interview:
http://www.oreillynet.com/pub/wlg/8274?wlg=yes

Also, Ezra’s migration story is excellent:
http://brainspl.at/articles/2005/11/03/from-start-to-launch-http-yakimaherald-com

There are some others, but these two were enough to sell my employers on
using RoR instead of the J2ee or PHP solution they were about to use :slight_smile:

Dylan