Ruby script/generate scaffold Product Admin hangs

I have a controller in which I define @responseAr as a new
line from responses table

def hello
@stimuliAr = Stimuli.find_all
@responseAr = Response.new
end

def knowname
a_response = Response.create(
:session_id => 1,
:stimuli_id => 0,
:keypress => 1,
:name => responseAr.name)
redirect_to :action => “hello”
end

in my hello.rhtml I have a form to collect a name to be
store

<%= start_form_tag(:action => “knowname”) %>
Name:
<%= text_field(“responseAr”, “name”) %>
<%= submit_tag(“Know Name”) %>
<% end_form_tag %>

I can write to the database if I type
:name => “testname”)
instead of
:name => @responseAr.name)
or
:name => responseAr.name)

How do I access responseAr.name which the form has saved to
save it to the table?
thank you for your help

Hi!

You need the Agile Web D. with Ruby on Rails book. And
probably the “Pickaxe” book.

I found something that works, but I don’t understand it

in my view page
<%= text_field(“responseAr”, “name”, “size” => “20”) %>

in my controller method
a_response = Response.create(
:session_id => 1,
:stimuli_id => 0,
:keypress => 1,
:name => params[:responseAr][“name”])

It works, but I don’t understand it, what is pararams,
the book says :variable, :attribute
the default content is taken from
@responseAr.name
but why is the result not put there? how am I
supposed to know it is in params? confused.

The text does not show right away in the text box, why not?

thanks for your help

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.

I believe 43things/people/places.com has been doing 1MM+ requests for
quite a while. The 37signals suite is doing more than 1.5MM+ requests
these days as well.

But these examples are not terribly interesting simply for the fact
that scaling Rails is largely uninteresting. It’s a solved LAMP
problem.

David Heinemeier H.
http://www.loudthinking.com – Broadcasting Brain
http://www.basecamphq.com – Online project management
http://www.backpackit.com – Personal information manager
http://www.rubyonrails.com – Web-application framework

Ian H. <harding.ian@…> writes:

Hi!

You need the Agile Web D. with Ruby on Rails book. And
probably the “Pickaxe” book.

Yes, it does sound like that is my problem, isn’t it, but I have both,
still it is all guess work. The info just isn’t there is in a way easy
to
grasp. What the book talks about is so much more complex than
what I am trying to do that I just don’t find the info/examples.

Are you sure that you are running Rails in development mode? You could
also
try setting up a different user for Rails to access MySQL. Try the
following.

From mysql:
create databasename;
grant all on databasename.* to ‘rails_user’@‘localhost’ identified by
‘password’;
flush privileges;

In your database.yml:
development:
adapter: mysql
database: databasename
username: rails_user
password: password
socket: /tmp/mysql.sock

David Heinemeier H. wrote:

But these examples are not terribly interesting simply for the fact
that scaling Rails is largely uninteresting. It’s a solved LAMP
problem.

But the fact that the solution applies to Rails isn’t necessarily
something people will assume, so that data point in itself is
interesting.

Here is what I learned after two days struggling with this:

To read from a table stimulis, I can run @stimuliAr = Stimuli.find_all
in the controller
and I can now access any of the rows with something like
@stimuliAr[0].image_url
where image_url is one of my fields.

then to capture a name from form and write to a table

I created a new row in the controller
@responseAr = Response.new

<%= start_form_tag(:action => “sortresponse”) %>
Name:
<%= text_field(“responseAr”, “name”, “size” => “20”) %>
<%= submit_tag(“Know Name”) %>
<% end_form_tag %>

text field would use @responseAr.name I believe if it was not empty to
put
something in the box.

the output of the form is in params. To look at params, run
render_text @params.inspect
in the controller.
In my case I got something like
{â??commitâ?=>â?Know Nameâ?,
�action�=>�sortresponse�,
�controller�=>�runexp�,
â??responseArâ?=>{â??nameâ?=>â?dudâ?}}

so the form returns the label on the submit button (you can have
several different submit buttons)
which includes the data in params[:responseAr][“name”]

to write this info to database, I wrote
a_response = Response.create(
:session_id => 1,
:stimuli_id => 0,
:keypress => 1,
:name => params[:responseAr][“name”])

I am not sure the a_response = is necessary.
this is how I wrote to the database.

This may not be the cleanest way but that is what I learned with
two days of work. I don’t know where to find that kind of reallly
basic information. I hope this post will help someone else.

What I need to do now is figure out session. Could someone give
me an idea of how complicated session is? What are the steps I need
to figure out. The book tutorial is too complex for me, and
I don’t understand the reference section on session right now.

I don’t want a login for right now, so the first time the page is
accessed, I need to create a fake id I guess which will identify
the computer.

Dylan S. wrote:

Hey Dan !

I really dig this interview:
O'Reilly Media - Technology and Business Training

Interesting, though not much on the implementation details.

Also, Ezra’s migration story is excellent:
Ruby on Rails Blog / What is Ruby on Rails for?

Again interesting, though it states that a lot of what’s being served is
static content. “We are getting around 60,000+ hits a day and thanks
rails page and fragment caching. This allows for content to be
regenerated once after it is updated and then written to a static .html
page that the webserver is able to serve at 1500+ requests/second. Then
the next time an update is made to the content of any page that is
cached, the cached file is regenerated as .html and served as a static
page until the next update.”

That might not work if the content is broader than it is deep, that is,
if you’re serving mostly user-specific pages or fragments of pages.

The “Agile Web D. with Rails” book gives these examples:
Basecamp by 37signals does 400,000 dynamic requests / day. The setup is
two servers (dual 2.4ghx xeons w/2gb of RAM each), apache1.3, fcgi.
rapidreporting.com tested it at 3000 req/sec on a test application, and
the real one (production) does about 300 req/sec. They use
lighttpd/fcgi.

A bit more info’s in that book.

Regards,
Jim

The “Agile Web D. with Rails” book gives these examples:

Basecamp:
2 x 2.4ghz Xeons w/2gb RAM
15 fcgi processes and 50-100 apache1.3 processes
400,000 dynamic requests/day

rapidreporting.com:
3000 req/sec on a test app across their 10 machine cluster
300 req/sec on their production environment
lighttpd and 10 fastCGIs.

More details in the book.

Regards,
Jim

David Heinemeier H. wrote:
[…]

But these examples are not terribly interesting simply for the fact
that scaling Rails is largely uninteresting. It’s a solved LAMP
problem.

Yes and no. To oversimplify, if you need to be able to handle peaks of,
say, 500 requests/second, and your Rails (or tomcat, or whatever) setup
will handle 100, then 5 servers should do it. If your Rails app will
only handle 5 requests/second, then you may be in trouble.

So application performance can’t be ignored, and more specifically,
solving the puzzle of Rails configuration for high performance is not
trivial.

On Feb 6, 2006, at 8:13 AM, James Nachlin wrote:

in trouble.

So application performance can’t be ignored, and more specifically,
solving the puzzle of Rails configuration for high performance is
not trivial.

What’s non-trivial?

It’s as easy, and thanks to lighhtpd (no, not part of Rails, but I
thank Rails for introducing me to it!) easier than mod_perl, and the
same as anything else running FCGI…

– Tom M.

solving the puzzle of Rails configuration for high performance is not
trivial.

Oh, scaling is never “easy”. It’s just that its a known,
well-described problem. We know what the elements and techniques are.
And they’re “boring” in Rails because they’re roughly the same as with
any other LAMP stack.

Now performance on a particular project can always be a bitch, but
it’s rarely so much about Rails as its about the business logic. And
of course, performance is different than scaling. You might have
terrible performance, like 5 req/sec, but still be able to throw tons
of hardware after it and still scale. And depending on your business
model, that might well still be immensely profitable. The cost per
request just needs to be less than the value of it.

David Heinemeier H.
http://www.loudthinking.com – Broadcasting Brain
http://www.basecamphq.com – Online project management
http://www.backpackit.com – Personal information manager
http://www.rubyonrails.com – Web-application framework

Tom M. wrote:
[…]

So application performance can’t be ignored, and more specifically,
solving the puzzle of Rails configuration for high performance is not
trivial.

What’s non-trivial?

It’s as easy, and thanks to lighhtpd (no, not part of Rails, but I
thank Rails for introducing me to it!) easier than mod_perl, and the
same as anything else running FCGI…

This is a serious question. Supposing that lighttpd is not suitable to
your application, or you can’t use it for some reason [*], then you can
use Apache 1.3 or 2, as I have been trying to do.

Setting up fastcgi using “external”, I find there are many times when
Rails does not give an error message with any information, just a 500 or
a blank response. If dispatch.fcgi dies when started as an external
server, it dies w/o error. There is little documentation on how to do
this. So, it was a struggle for me.

Eventually, I did get it working [**] thanks to the people on this list,
but there are still serious issues.

This is not to put any blame on the Rails team. It is just a newish
system. The fcgi documentation is sparse as well, and error reporting
there is not great. So, non-trivial, overall.

Regards,
Jim

http://article.gmane.org/gmane.comp.web.lighttpd/3287
**
INITIAL RUBY ON RAILS BENCHTEST

This is on a laptop running linux 2.6, 512MB RAM, 1.7 GHz pentium M.
These figures are for relative comparison only, and do not reflect how
these systems would run on a well-tuned server. The person who set
these up has several years using the Apache httpd on a professional,
high volume web site, and has no experience (<1 month) with lighttpd.

STATIC PAGE FOR COMPARISON:
$ ab -c10 -n1000 -k http://ruby.local:8000/index.html
Apache/2.0.53, fcgi: 564.99 [#/sec] (mean)
Apache/1.3.34, fcgi: 1236.24 [#/sec] (mean)
lighttpd 1.4.9, fcgi: 3270.16 [#/sec] (mean)

DUMMY RAILS CONTROLLER:
$ script/generate controller foo hello
$ ab -c10 -n1000 -k http://ruby.local:8000/foo/hello
Apache/2.0.53, fcgi: 9.65 [#/sec] (mean) <---- using “dynamic” fcgi
method
10.13 [#/sec] (mean) <---- using “static” with
-processes 2
9.98 [#/sec] (mean) <---- using “static” with
-processes 4
136.24 [#/sec] (mean) <---- using “external”
with tcp sock **
Apache/1.3.34, fcgi: *
Apache/2.0.53, cgi: 0.79 [#/sec] (mean)
lighttpd 1.4.9, fcgi: 195.70 [#/sec] (mean) <---- using “external” with
tcp sock ***

$ ab -c100 -n10000 -k http://ruby.local:8000/foo/hello
Apache/2.0.53, fcgi: 109.79 [#/sec] <---- using “external” with
tcp sock **

NOTES

  • Can’t get it working. Fails w/ only a “500” from server, no further
    error msg.
    ** This method seems to support only one external fcgi server under
    Apache, essentially giving you a single-threaded server.
    spin script:
    #!/bin/sh
    /home/jim/rubystuff/testapp/script/process/spinner
    -c '/home/jim/rubystuff/testapp/script/process/spawner -p 19999 -i 1

    -d
    *** hint: delete the /tmp/ruby-sess* files owned by root

Ezra Z. wrote:
[…]

room to grow still. My estimate is that we will be able to keep up with
I have no reservations that rails can handle as big of a site as
you want. You just need to make the right decisions about your apps
design and get the right hardware for the amount of traffic you expect
to serve.
[…]

Hi Ezra,

This is very good to hear, but so far I can’t reproduce these results or
anything near them using

I need to use Apache. So far it seems that with fcgi external servers
Rails will run single-threaded, and with “static” or “dynamic” fcgi,
performance is <10 req/sec. on my test box.

I know that people have made this work, and that Rails will scale, it is
just a matter of figuring out how, which I have not done yet.

Jim

<10/second sounds like you’re CGI, not FCGI.


– Tom M.

On Feb 6, 2006, at 8:00 AM, Jim N. wrote:

is, if you’re serving mostly user-specific pages or fragments of

Regards,
Jim

Jim-

I wrote that article in September of 05 when we launched the new

site. And yes most stuff was cached then. Since then our traffic has
increased quite a bit. Yesterday we served about 50,000+ cached page
views and about 45,000+ dynamic page views. This is because we have
added a bunch of functionality to the application and a lot of it
cannot be page cached.

But the whole site runs off of one dual xserve and we have tons of

room to grow still. My estimate is that we will be able to keep up
with 400-500k page views/day before we will need any new hardware.
Some of this performance increase is because the initial launch of
the site was on rails 0.12 - 0.13, I don’t remember exactly which
one. But running under rails 1.0.0 is much faster and the performance
keeps getting better.

Also, most very high traffic sites will make good use of caching

everywhere they can. Its mostly about finding the balance between the
functionality you need per page and your caching options available
for said page.

I have no reservations that rails can handle as big of a site as you

want. You just need to make the right decisions about your apps
design and get the right hardware for the amount of traffic you
expect to serve.

Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster

509-577-7732
[email protected]

On Feb 6, 2006, at 10:56 AM, James Nachlin wrote:

application and a lot of it cannot be page cached.
options available for said page.

I need to use Apache. So far it seems that with fcgi external
servers Rails will run single-threaded, and with “static” or
“dynamic” fcgi, performance is <10 req/sec. on my test box.

I know that people have made this work, and that Rails will scale,
it is just a matter of figuring out how, which I have not done yet.

Jim

Jim-

I first launched the newspaper site under apache1.3.x/fcgi and soon

realized how it wasn’t performing very well at all for dynamic pages.
And apache/fcgi is notorious for those random 500 error messages that
are intermittent. So after using apache/fcgi for the site for one
week I decided to use lighttpd instead. The difference was black and
white. Apache is a great all around webserver and can do a great job
for some rails apps. But I have found that lighttpd was so much
faster and so much more stable for me that the only time I use apache
with my rails projects now is as a front end proxy to lighty on a
higher port. Even with the overhead of apache->lighty->rails->lighty-

apache, this set up was faster then standalone apache/fcgi.

I understand that people are very used to apache servers and may be

reluctant to switch to lighty. But this will be a serious impediment
to your production environment until the new mod_proxy_fcgi comes out
for apache. i am hoping that that new apache module will solve these
problems. But for right now, lighty is IMHO the better choice for
most rails applications.

Feel free to contact me off list. I would be happy to share

configuration files with you if you need.

Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster

509-577-7732
[email protected]

I must now recant some of my previou statements. There was an error in
my httpd.conf such that the “-initial-env RAILS_ENV=test” was not
getting passed. This means that the benchtest was running in
development mode under apache2.

I am now getting >100 req/sec in test or production mode, using the
dynamic fcgi method and unix sockets!

Regards,
Jim

Tom M. wrote:

<10/second sounds like you’re CGI, not FCGI.

– – Tom M.

No. CGI is <1/sec. If anyone’s getting better performance with FCGI
dynamic or static on Apache2, I’d like to hear how. Glad to share my
httpd.conf and anything else.

Sincerely,
Jim N.