Hello After upgrading to ruby 1.8.2, finally got rails to install properly. Now, following the tutorial, I found a couple of things: First, apparently rails tries to establish local mysql connections using "/tmp/mysql.sock" which mandrake does not use. In mandrake 10.1, this file is located at "/var/lib/mysql/mysql.sock". The solution is to create a simlink /tmp/mysql.sock -> /var/lib/mysql/mysql.sock, but I wonder why rails doesn''t try to connect to localhost using TCP/IP if it can''t find the socket (emiting a warning, perhaps) Another question: I have a little mysql table which I''m using to test rails. It is named "comentarios". Right now I''m in section 4.3 (from tutorial), in which you add the line "scaffold :comentario" to "comentario_controller.rb". The problem is this: whenever I try the links "Show" / "Edit" / "Destroy" from http://localhost:3000/comentario/ there is some sort of error: ActiveRecord::RecordNotFound in Comentario#show Couldn''t find Comentario without an ID |script/server:51| Show framework trace <http://localhost:3000/comentario/show#> |/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.7.0/lib/active_record/base.rb:283:in `find'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/scaffolding.rb:106:in `show'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/base.rb:681:in `send'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/base.rb:681:in `perform_action_without_filters'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/filters.rb:294:in `perform_action_without_benchmark'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/benchmarking.rb:30:in `perform_action_without_rescue'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/benchmarking.rb:30:in `measure'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/benchmarking.rb:30:in `perform_action_without_rescue'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/rescue.rb:79:in `perform_action'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/base.rb:323:in `send'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/base.rb:323:in `process'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.5.0/lib/action_controller/base.rb:266:in `process'' /usr/local/lib/ruby/gems/1.8/gems/rails-0.10.0/lib/dispatcher.rb:32:in `dispatch'' /home/jpablo/Documents/proyectos/Comentario/public/dispatch.rb:10 /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.0.0/lib/active_support/dependencies.rb:182:in `load'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.0.0/lib/active_support/dependencies.rb:182:in `load'' /usr/local/lib/ruby/gems/1.8/gems/rails-0.10.0/lib/webrick_server.rb:82:in `handle_dispatch'' /usr/local/lib/ruby/gems/1.8/gems/rails-0.10.0/lib/webrick_server.rb:34:in `do_GET'' /usr/local/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35:in `__send__'' /usr/local/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35: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:155:in `start_thread'' /usr/local/lib/ruby/1.8/webrick/server.rb:144:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'' /usr/local/lib/ruby/1.8/webrick/server.rb:94:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:89:in `each'' /usr/local/lib/ruby/1.8/webrick/server.rb:89:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:79:in `start'' /usr/local/lib/ruby/gems/1.8/gems/rails-0.10.0/lib/webrick_server.rb:20:in `dispatch''| Request *Parameters*: {:controller=>"comentario", :action=>"show"} Show session dump <http://localhost:3000/comentario/show#> --- flashes: 0 flash: {} Response *Headers*: {"cookie"=>[], "Cache-Control"=>"no-cache"} Show template parameters <http://localhost:3000/comentario/show#> First I thought the problem was due to my table not having a primary key. Thus I added one. But the error remais. What is "ID" in this context? Regards Juan Pablo
On Wed, 2005-03-02 at 18:34 -0600, Juan Pablo Romero wrote:> Hello > > After upgrading to ruby 1.8.2, finally got rails to install properly. >> I have a little mysql table which I''m using to test rails. It is named > "comentarios". Right now I''m in section 4.3 (from tutorial), in which > you add the line "scaffold :comentario" to "comentario_controller.rb". > > The problem is this: whenever I try the links "Show" / "Edit" / > "Destroy" from > > http://localhost:3000/comentario/ > > there is some sort of error: > > > ActiveRecord::RecordNotFound in Comentario#show > > Couldn''t find Comentario without an ID> > First I thought the problem was due to my table not having a primary > key. Thus I added one. But the error remais. > > What is "ID" in this context?ID should be an auto incrementing id field in the comentario table. It specifically identifies a record in that table to be edit/show/destroy. It is part of the convention over configuration concept of rails. Scaffold is then expecting it. It would be possible to do your find a different way. It would be possible for you to change your controller in such a way as to find_first_by_xxx() instead of find() and provide it back to the original variable for the view to display, but it would end up requiring you to change it for every controller you chose not to do the standard way. -- Steven Critchfield <critch-wQLwMjUOumVBDgjK7y7TUQ@public.gmane.org>
On 03/03/2005, at 11:34 AM, Juan Pablo Romero wrote:> First, apparently rails tries to establish local mysql connections > using "/tmp/mysql.sock" > which mandrake does not use. In mandrake 10.1, this file is located at > "/var/lib/mysql/mysql.sock". > > The solution is to create a simlink /tmp/mysql.sock -> > /var/lib/mysql/mysql.sock, > but I wonder why rails doesn''t try to connect to localhost using > TCP/IP if it can''t find the socket (emiting a warning, perhaps)The document for the MySQL adaptor mentions this, though its not clear how to use the parameter options: http://ar.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ MysqlAdapter.html Just specify "socket /var/lib/mysql/mysql.sock" ''in your database config after host, port, username, password etc And for your other question I don''t have an answer unfortunately. - tim lucas
>> The problem is this: whenever I try the links "Show" / "Edit" / >> "Destroy" from >> >> http://localhost:3000/comentario/ >> >> there is some sort of error: >> >> ActiveRecord::RecordNotFound in Comentario#showThe last response might not have stated the answer clearly enough... Methods like "show" or "destroy" need to operate on some record. So a URL like this:>> http://localhost:3000/comentario/editdoesn''t really make any sense. If you have 100 "commentarios" in your database, which one are you editing? The solution is really simple: specify an id for the record you want to show:>> http://localhost:3000/comentario/edit/1"1" is the id. It is the primary key in your commentario table.
> The document for the MySQL adaptor mentions this, though its > not clear > how to use the parameter options: > http://ar.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ > MysqlAdapter.html > > Just specify "socket /var/lib/mysql/mysql.sock" ''in your database > config after host, port, username, password etcI wonder if it might be simplier to edit/create a my.cnf file and add this line: [client] /path/to/socket/ Reference: http://dev.mysql.com/doc/mysql/en/problems-with-mysql-sock.html As far as using TCP/IP, from what I''ve read in a book that was publihsed two years ago, only the Windows version uses TCP/IP to connect... don''t know why *nix doesn''t though.
Andrew Otwell wrote:> >>> The problem is this: whenever I try the links "Show" / "Edit" / >>> "Destroy" from >>> >>> http://localhost:3000/comentario/ >>> >>> there is some sort of error: >>> >>> ActiveRecord::RecordNotFound in Comentario#show >> > > The last response might not have stated the answer clearly enough... > Methods like "show" or "destroy" need to operate on some record. So a > URL like this: > >>> http://localhost:3000/comentario/edit >> > > doesn''t really make any sense. If you have 100 "commentarios" in your > database, which one are you editing? The solution is really simple: > specify an id for the record you want to show: > >>> http://localhost:3000/comentario/edit/1 >> > > "1" is the id. It is the primary key in your commentario table.D''oh! I finally got it. The primary key in the DB must be called "id". I somehow assumed it was enough to define some column as a key and have rails use it. Back to learning rails now. Thanks to all. Juan Pablo> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Juan Pablo Romero wrote:> D''oh! > I finally got it. The primary key in the DB must be called "id". > I somehow assumed it was enough to define some column as a key and have > rails use it.That would be an extremely nice feature. Please post it to http://dev.rubyonrails.com/newticket as an enhancement request. jeremy
Oy... trying to start the SQL semantic vs non-semantic primary key debate? The convention for ''id'' as the primary key is based on using non-semantic primary keys, which for the most part, just work better on the database side... On Thu, 03 Mar 2005 14:05:06 -0800, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> Juan Pablo Romero wrote: > > D''oh! > > I finally got it. The primary key in the DB must be called "id". > > I somehow assumed it was enough to define some column as a key and have > > rails use it. > > That would be an extremely nice feature. Please post it to > http://dev.rubyonrails.com/newticket as an enhancement request. > > jeremy > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >