[Rails] can www.example.com/...#!... always use controller=redirect
In Ruby on Rails routing (using route.rb), can it say, for any URL having the form: www.example.com/ ... #! ... then use controller `redirect` ? This is so that in AJAX, some page can tag the `#!` at the end of URL so that the real content of interest is the part after the `#!` -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] a few steps for a database with polymorphic association?
I thought it could be created in a few steps but it can't yet: rails poly cd poly ruby script/generate scaffold animal name:string obj_type:string obj_id:integer rake:migrate ruby script/generate scaffold human name:string passportNumber:string rake:migrate ruby script/generate scaffold dog name:string registrationNumber:string rake:migrate and now change app/models/animal.rb to: class Animal ActiveRecord::Base belongs_to :obj, :polymorphic = true end and run ruby script/server and go to http://localhost:3000 I thought on the server then if I create an Michael, Human, J123456 and then Woofie, Dog, L23456 then the database will have entries in the Dogs table and Humen or Humans table as well as in the Animals table? But only the Animals table has records, Dogs and Humen do not for some reason. Is there some steps missing? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] How not to include the same javascript files more than once?
In Ruby on Rails, if a partial (such as _msgbox.html.erb) need to use Javascript by javascript_include_tag :defaults but then, the page layout or other view may also have that same line, so the same javascript files will be included multiple time? Is there a way to tell Rails just to include it at most once? kind of like the PHP ways of require_once or include_once -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] map.connect will not create connect_path and connect_url?
In Ruby on Rails, routes.rb, if we create a named route map.something :a/:b, :controller = 'foobar' it will also create something_path and something_url which are two methods usable in the controller and in the view. Does map.connect create something like that too? Otherwise, isn't map.connect somewhat disadvantaged in this way? I checked that connect_path and connect_url both aren't created automatically. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] How come need to get MySQL to work in a strange way?
The following is an error for using RoR with MySQL: C:\ror\shov17rake db:migrate (in C:/ror/shov17) !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql. rake aborted! 193: %1 is not a valid Win32 application. - c:/ruby/lib/ruby/gems/1.8/gems/mys ql-2.8.1-x86-mingw32/lib/1.8/mysql_api.so (See full trace by running task with --trace) C:\ror\shov17gem update mysql Updating installed gems Nothing to update C:\ror\shov17gem list mysql *** LOCAL GEMS *** mysql (2.8.1 x86-mingw32) == searching the net got this page: http://www.ninjacoding.net/archive/2010/01/11/the-bundled-mysql.rb-driver-has-been-removed-from-rails.aspx Quoted: After tearing my hair, installing and reinstalling the MySQL 2.8.1 gem goggling for answers for an hour I finally found the answer that helped me. The in the reply from by Hao Zhao, he pointed out that the 2.2.2 version of Rails does not support the MySQL 5.x client! The solution to this is this: Download an older version of the MySQL client library from http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll Copy the downloaded file to c:\Your Ruby install folder\bin That’s it! I could go mad right now but I’m too happy to finally have found this. End of Quote... How come this is not documented in Rails website or its wiki http://wiki.rubyonrails.org/database-support/mysql I wonder... and it feel a pretty strange way to make something working. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: What kind of Ruby / Erb is allowed inside HAML's :javasc
Marnen Laibow-Koser wrote: 1) -# to add comment but not to show it to the public Use a JS minifier. 2) using if else to output something based on some condition 3) using loop Use JavaScript control structures for these, not Ruby control structures. 4) providing values to javascript code by json Put the JSON in a (hidden) div, have the JavaScript read its content. JS Minifier when there are 5 lines of code? Also, I think we can always do things another way... but just that why embedding values from Ruby to Javascript is bad, while hiding them first in a div and read it back from the div is good? (suppose they are simple keywords from our db which keywords like shirt, shorts, jacket which will not cause any javascript injection by user input.) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: What kind of Ruby / Erb is allowed inside HAML's :javasc
Marnen Laibow-Koser wrote: JS Minifier when there are 5 lines of code? If there are only 5 lines of code, why do you need private comments in the first place? Do you often see other people's way of doing things needing to abide to your rule book? Such as: if there are only n lines of Javascript code, they shall never have private comments there. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: What kind of Ruby / Erb is allowed inside HAML's :javasc
Marnen Laibow-Koser wrote: Jian Lin wrote: Marnen Laibow-Koser wrote: JS Minifier when there are 5 lines of code? If there are only 5 lines of code, why do you need private comments in the first place? Do you often see other people's way of doing things needing to abide to your rule book? Such as: if there are only n lines of Javascript code, they shall never have private comments there. You missed my point. It wasn't shall never. My point was this: a 5-line routine should normally not need comments. If you need comments on something that short, perhaps your code isn't as clearly written as it should be... A reason may be, a comment that says TODO: we don't have enough time to do more than this right now. talk to Simon for when it will be done -- or any other similar comment -- may not be totally appropriate for the public. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: What kind of Ruby / Erb is allowed inside HAML's :javasc
Marnen Laibow-Koser wrote: Or...hmm. Check out CoffeeScript; it's a bit like Haml for JS. if only there is a Ruby to JS converter. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: What kind of Ruby / Erb is allowed inside HAML's :javasc
Marnen Laibow-Koser wrote: If you think you need Ruby in your JS, you've got a design problem. Fix it. i can think of a few cases where Ruby might be wanted inside of Javascript output: 1) -# to add comment but not to show it to the public 2) using if else to output something based on some condition 3) using loop 4) providing values to javascript code by json -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: Can Rails cache a Controller as long as code not change
Marnen Laibow-Koser wrote: foo.js?1273424325 which is to use the cached version as long as there is no code change, but recompile it when there is code change? Because it's a different kind of caching. JavaScript caching simply involves using the browser cache for included files, whereas controller caching involves Ruby objects in memory on the server. I know that they are different kind of caching, -- now can't the same principle be used? When newer, reload / recompile it -- when older, no need to reload or recompile. so when the controller code in cache is newer, then no need to re-compile. when it finds that the controller code is newer, then recompile it. by the way, what is this caching? I thought it is re-interpreted each time? So what is the caching for -- it is not byte code like in Python? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] test db is same as dev db and ask for sure: Yes/No?
Is it feasible that when running unit test or functional test, when it detects that the test db is the same as the development db, then give a warning: are you sure? the whole db will be wiped cleaned - Yes/No. Because some people who are new to Rails and even experienced people may make a simple mistake and wipe out their whole database. (ours is a 3GB text mysqldump, so to restore it, it takes about 4 hours to reconstruct it. anybody know a better way to backup/restore it instead of 4 hours by the way?) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Can Rails cache a Controller as long as code not changed?
At work, we have a situation where when script/server is run, then all the controller code is cached. This is to speed up the development server. But that will mean that whenever we change the controller code, we need to restart the server. So we can turn off the caching of controller code all together. But can't there be mechanism that is similar to the inclusion of javascript foo.js?1273424325 which is to use the cached version as long as there is no code change, but recompile it when there is code change? Maybe because we use HAML and SASS a lot, loading some page (such as the homepage of the site) can take 40 seconds on the dev environment and it is quite long. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] What kind of Ruby / Erb is allowed inside HAML's :javascript
It seems that inside of HAML's :javascript filter, no Ruby code is allowed, not even a comment. So this is NOT allowed: :javascript - 1.upto(10) do |i| :javascript -# just a comment not to show to public (somebody said there is not way to hide comment like that inside a :javascript filter. Is that true? but it seems the only thing allowed is :javascript $('#aDiv').html('#{a_ruby_variable}'; only this #{ } is allowed. Nothing else that is Ruby is allowed? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: What kind of Ruby / Erb is allowed inside HAML's :javascript
Jian Lin wrote: but it seems the only thing allowed is :javascript $('#aDiv').html('#{a_ruby_variable}'; correction: (missing the ending paren) :javascript $('#aDiv').html('#{a_ruby_variable}'); -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] cookie has key/value pairs and lost order after JSON decode
If a cookie has several items, and is encoded as JSON text as the value of the cookie, the order is actually apparent in the cookie's text But if JSON.decode is used: ActiveSupport::JSON.decode(cookies['item_list']) and the result is actually in a hash, then the ordering is lost... Is it true that if the original JSON object has an array of hashes (1 key and 1 value), then the order can be preserved? But what if the original JSON object was a hash of key / value pairs, and is already in many users' cookies, then is there a way to somehow keep the order? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] RJS suitable for doing interactivities within a webpage?
RJS is very good for sending Javascript code back to the browser saying Your AJAX is successful and by the way you can update the UI to signal to the user using the following Javascript I am going to send you. How about other webpage interactivities, dynamic HTML, is RJS suited for doing that as well, or is Prototype.js, or jQuery, or plain Javascript statically loaded with the webpage, still more suited for doing it? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] does changing to_param() have any side effect?
In some book, it is recommended that to_param is changed to class Story ActiveRecord::Base def to_param #{id}-#{name.gsub(/\W/, '-').downcase} end end so that the URL is http://www.mysite.com/stories/1-css-technique-blog instead of http://www.mysite.com/stories/1 so that the URL is more search engine friendly. So probably to_param() doesn't need to be used by other parts of Rails that changing it may have any side effect? Or maybe the only purpose is to construct a URL for linking? Another thing is, won't it require to limit the URL size to be less than 2k in length -- will it choke IE if it is more than 2k or maybe the part more than 2k is just ignored by IE and so the URL still works. It might be better to be limited to 30 or 40 characters or something that will make the URL not exceedingly long. Also, the `ri` doc of to_param: class User ActiveRecord::Base def to_param # overridden name end end if to_param is changed like that, then the link actually won't work, as http://www.mysite.com/stories/1-css-technique-blog will work, but http://www.mysite.com/stories/css-technique-blog will not work as the ID is missing. Are there other ways to change the to_param method? **Update:** on second thought, maybe http://www.mysite.com/stories/css-technique-blog won't work well if there are many webpages with similar title. but then http://www.mysite.com/user/johnchan will work. Will it be params[:id] being johnchan? So then we will use user = User.find_by_login_name(params[:id]) to get the user. So it just depends on how we use the param on the URL. C:\rorri ActiveRecord::Base#to_param ActiveRecord::Base#to_param to_param() Returns a String, which Action Pack uses for constructing an URL to this object. The default implementation returns this record's id as a String, or nil if this record's unsaved. For example, suppose that you have a User model, and that you have a +map.resources :users+ route. Normally, +user_path+ will construct a path with the user object's 'id' in it: user = User.find_by_name('Phusion') user_path(user) # = /users/1 You can override +to_param+ in your model to make +user_path+ construct a path using the user's name instead of the user's id: class User ActiveRecord::Base def to_param # overridden name end end user = User.find_by_name('Phusion') user_path(user) # = /users/Phusion -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Can RoR handle AJAX Response by Static Javascript code?
So it looks like on RoR, when Ajax (using form_remote_tag) returns a success code, Javascript is also returned to handle the visual effects. using Fiddler, I do see the following response: try { Element.update(vote_score, Score 58); $(vote_score).visualEffect(highlight); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.update(\vote_score\, \Score 58\);\n$(\vote_score\).visualEffect(\highlight\);'); throw e } Will there be situation where the code is quite big (like 1 or 2k) that RJS can use some sort of static Javascript already loaded to handle the effect? Is there any other ways to use static Javascript already loaded with the page? Must it be just raw Javascript and use the Prototype's Ajax success response to call the static Javascript code, or can it be some Rails mechanism related to RJS? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Two RJS visual effects will happen at the same time?
I was going to change the background of a div from white to red and then from red back to white, so this is used in an RJS file: page[:vote_score].visual_effect :highlight, :startcolor = '#ff', :endcolor = '#ff' page[:vote_score].visual_effect :highlight, :startcolor = '#ff', :endcolor = '#ff' But looks like they happen at the same time, instead of one after another. Is there a way to make it happen one after another? the Javascript sent to the browser is: try { $(vote_score).update(Score 63); $(vote_score).visualEffect(highlight, {endcolor:#ff,startcolor:#ff}); $(vote_score).visualEffect(highlight, {endcolor:#ff,startcolor:#ff}); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('$(\vote_score\).update(\Score 63\);\n$(\vote_score\).visualEffect(\highlight\, {\restorecolor\:\#ff\,\endcolor\:\#ff\,\startcolor\:\#ff\});\n$(\vote_score\).visualEffect(\highlight\, {\endcolor\:\#ff\,\startcolor\:\#ff\});'); throw e } -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] why story.votes return Array, but story.votes.create works?
In Ruby on Rails, say a Story object can has_many Vote objects (a story is voted hot by many users). So when we do a s = Story.find(:first) s is a Story object, and say s.votes returns [] and s.votes.class returns Array So clearly, s.votes is an empty Array object. At this time, when s.votes.create is called, it actually invokes a method of the Vote class? How come an Array class object can invoke a Vote class method? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: why story.votes return Array, but story.votes.create works?
Frederick Cheung wrote: On May 23, 7:10�am, Jian Lin li...@ruby-forum.com wrote: So clearly, s.votes is an empty Array object. Actually it's not. It's an AssociationProxy object pretending to be an instance of Array Fred not like this? irb(main):010:0 class Foo irb(main):011:1 def class irb(main):012:2 return Fixnum irb(main):013:2 end irb(main):014:1 end = nil irb(main):015:0 f = Foo.new = #Foo:0x4799ce8 irb(main):016:0 f.class = Fixnum irb(main):017:0 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: Re: What happens when Rails 1.3.5 is installed on top of 2.3.5?
Rick Denatale wrote: That's actually not the whole story, and excerpt from the output of gem help install: Description: The install command installs local or remote gem into a gem repository. For gems with executables ruby installs a wrapper file into the executable directory by default. This can be overridden with the --no-wrappers option. The wrapper allows you to choose among alternate gem versions using _version_. For example `rake _0.7.3_ --version` will run rake version 0.7.3 if a newer version is also installed. What about if Rails 2.3.5 is installed and then 1.2.5 is installed? It seems like after that rails -v will still give 2.3.5. So the default executable is not overwritten or linked to 1.2.5 but to the newest version. Also, if we run rails _1.2.5_ the won't all the supporting files, script, etc, etc also need to be versioned? So probably that is automatically taken care of as well? So, supposedly, we can install rails in ANY ORDER -- 2.3.5 first, and then 2.2.2 and then 1.2.5 and they still all work well, and the default one is still the 2.3.5 version? wow, if only Windows application can do that too... -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: What happens when Rails 1.3.5 is installed on top of 2.3.5?
pepe wrote: Just in case it applies here is an extract from the Pickaxe book (Second edition, page 217): Threre's a subtlety when it comes to installing different versions of the same application with RubyGems. Even though RubyGems keeps separate versions of the application's library files, it does not version the actual command you use to run the application. As a result, each install of an application effectively overwrites the previous one. so that means it will be safest if i re-run gem install rails or gem install rails -v2.3.5 again? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] What happens when Rails 1.3.5 is installed on top of 2.3.5?
On a Mac running Snow Leopard, the Rails version was 2.3.5 (by using rails -v) and then I used gem install to install about 20 things, and maybe there was a line on the instructions that was there in the past that says gem install rails -v=1.3.5 and I ran it anyways, thinking that maybe 1.3.5 is a different version number... and it installed 5 gems (as i remember). Will that actually affect the current rails? Even after the installation, when I use rails -v it still says 2.3.5 and also if it is gem list rails it would list something like rails (2.3.5, 2.3.2, 1.3.5) so looks like they exist nicely with each other without affecting one another? thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Easy way to make Rails use MySQL on Windows?
I set up Rails from scratch using the methods on: http://rubyonrails.org/download and also: gem install sqlite3-ruby download sqlite3.dll into c:\ruby\bin change config/database.yml adapter lines for dev, test, prod all to sqlite3 so sqlite3 can be used now... but what if i also installed MySQL on c:\Program Files Is there an easy way to make Rails work with MySQL? if i use gem install mysql there will be lots of errors saying No definition for next_result ... -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: Easy way to make Rails use MySQL on Windows?
Jette Chan wrote: Yes, gem install mysql is needed. But, I'm not sure what do you mean lots of errors. Maybe you should post your errors here. sure, a sample run is: C:\Software Projects\ror\shov6gem install mysql Successfully installed mysql-2.8.1-x86-mingw32 1 gem installed Installing ri documentation for mysql-2.8.1-x86-mingw32... No definition for next_result No definition for field_name No definition for field_table No definition for field_def No definition for field_type No definition for field_length No definition for field_max_length No definition for field_flags No definition for field_decimals No definition for time_inspect No definition for time_to_s No definition for time_get_year No definition for time_get_month No definition for time_get_day No definition for time_get_hour No definition for time_get_minute No definition for time_get_second ... -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: Re: Easy way to make Rails use MySQL on Windows?
Jette Chan wrote: OK. Now I know... I thought t you can see 1 gem installed So, it means you've already finished install mysql gem now. And the following errors come from when installation the documentation. Actually you already can use this gem now. but when i use http://localhost:3000 and click on the About your application’s environment the box will say error... right now MySQL is a command line app, does it need to be run as a background process? and i guess when i create the project, it is better to use rails myapp -d mysql ? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Is there a way not to break 3 lines of code into 3 % % ?
In the view code, say it is % @stories.each do |s| % %= div#{h s.inspect}/div % % end % it would be breaking the code into 3 % % and %= % is there a way to just have one % % or %= % so as to keep the code more flowing together? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: Is there a way not to break 3 lines of code into 3 % % ?
Philip Hallstrom wrote: In the above case you could do this... %= @stories.map {|s| content_tag(:div, h(s.inspect)) }.join % i was at first worried that if the print out is long, like a few hundred lines, then it can create many string objects. using join looks like will create only n + 1 string objects... if using inject or something, it might be creating about 2n string objects, each one longer than the previous ones. that's why is it true that some text #{ } and then something more #{ } is better since it is one string object created while some text + expression + and then something more + expression will create 4 string objects and therefore running slower? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: Is there a way not to break 3 lines of code into 3 % % ?
Jian Lin wrote: using join looks like will create only n + 1 string objects... ah, on second thought, doesn't the join() method actually will create n string objects too? (the next one longer than a previous one), so it would be creating 2n string objects too. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] to loop through the instance variables of ActiveRecord?
to wrap each instance variable of an ActiveRecord object between td and /td, is there a way to loop through them, at least in the debug mode, no matter there is getter methods to get them or not, or at least the ones with the getter methods? Such as % @stories.each do |s| % %= tr % % s.each_property do |i| % %= td#{h i}/td\n % % end % %= /tr\n % % end % ? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: to loop through the instance variables of ActiveRecord?
Philip Hallstrom wrote: %= td#{h i}/td\n % % end % %= /tr\n % % end % @stories.attributes http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002348 -philip Great thanks. So I have come up something like this: the row == 1 check is to print the header style table { border-collapse: collapse } td, th { border: 1px solid #ccc; padding: 0.33em } th { background: #eee } /style %= table\n % % row = 1 % % @all_stories.each do |s| % % if row == 1 % %= tr % % s.attributes.each do |i| % % p i % %= th#{h i[0]}/th\n % % end % %= /tr\n % % end % %= tr % % s.attributes.each do |i| % % p i % %= td#{h i[1]}/td\n % % end % %= /tr\n % % row += 1 % % end % %= /table\n % it might be better if the internal loop counter can be used for looping @all_stories so that now extra local variable row is needed. also, the use of i[0], i[1] seems a little less structured than if i.attr_name, i.attr_value can be used. the row == 1 situation also seems like somewhat not adhering to DRY. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: Re: to loop through the instance variables of ActiveRecord?
Jian Lin wrote: yes, column_names gave a better order: C:\Software Projects\ror\shov10ruby script/console Loading development environment (Rails 2.3.5) Story.column_names = [id, name, link, created_at, updated_at] so the code can be: style table { border-collapse: collapse } td, th { border: 1px solid #ccc; padding: 0.33em } th { background: #eee } tr:hover { background: #eee } /style %= ppptable\n % % row = 1 % % @all_stories.each do |s| % % if row == 1 % %= tr % % @column_names.each do |i| % %= th#{h i}/th\n % % end % %= /tr\n % % end % %= tr % % @column_names.each do |k| % %= td#{h s.attributes[k]}/td\n % % end % %= /tr\n % % row += 1 % % end % %= /table\n % I found that either s.attributes[k] or s.send(k) can be used. the second one is to invoke the getter method and it gave a slight different version of the datetime object. kind of interesting that in script/console, i get s.created_at = Thu, 13 May 2010 09:22:50 UTC +00:00 s.send(created_at) = Thu, 13 May 2010 09:22:50 UTC +00:00 but on the webpage, i get a different format: 2010-05-13 09:23:58 UTC -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] way to divide long article and store in database
I wonder if a Ruby on Rails developer has encounter this before: suppose it is a long article (say 100,000 words), and I need to write a Ruby file to display page 1, 2, or page 38 of the article, by display.html.erb?page=38 but the number of words for each page can change over time (for example, right now if it is 500 words per page, but next month, we can change it to 300 words per page easily). What is a good way to divide the long article and store into the database? P.S. The design may be complicated if we want to display 500 words but include whole paragraphs. That is, if we are showing word 480 already but the paragraph has 100 more words remaining, show those 100 words anyway even though it exceeds the 500 words limit. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: way to divide long article and store in database
Jonathan Rochkind wrote: Jian Lin wrote: I wonder if a Ruby on Rails developer has encounter this before: suppose it is a long article (say 100,000 words), and I need to write a Ruby file to display page 1, 2, or page 38 of the article, by display.html.erb?page=38 but the number of words for each page can change over time (for example, right now if it is 500 words per page, but next month, we can change it to 300 words per page easily Why divide it in the database? Store it one field in the database, and when you fetch it from the database just perform the logic to find page=38 and then display that. is it true that it all the 100,000 words are in one record (one row), then every time, the whole field needs to be retrieved. If we assume one work is about 6 characters long (with the space), then it is 600kbyte per read. I hope to make it read as needed... 500 words and about 3kbyte read per page each time. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: a way that helper functions not produce XHTML but HTML?
Lee Smith wrote: Trying to change the way Rails lays down a stylesheet include is really a waste of time. This HTML vs XHTML syntax only matters if you're validating...otherwise, the browser renders it as HTML. Don't waste your time and definitely update your browser. i think there are time when i actually want to validate my page output... especially if the page is complicated with layouts and div's. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: a way that helper functions not produce XHTML but HTML?
hm... you know what, my coworker had this one line: div style=clear:both / and the page would still validate perfectly as XHTML, but IE will render it differently from FF. FF will take it as a closing div. IE will not take it as a closing div. so I will have perfectly validated code that behaves differently on two popular browsers. and i can communicate to all my coworkers. but it is hard if the code is already 2000 files and was written for the past 2 years and many coworkers were even gone at other companies. i still need to deal with all the existing code. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: why does this comment create a compile error
pepe wrote: I've run into the same problem several times before and never thought too much of it, just made the correct change to be able to compile and kept going. Now that I think about it I might have an answer. The ruby code is just what it is between % and %. Those 'delimiters' are just to tell the engine something like 'ruby code coming'. The = sign is probably actually a method call equivalent to 'puts' (I might have read that somewhere in the AWDWR book). The rest of the line is the parameter to the method. By putting the # sign after the = sign we are actually commenting out the parameter to the method but leaving the method call in place. The interpreter might not know what to do with a method call with no parameter (maybe a parameter is mandatory for the = sign method?) and burps. However if you put the # sign in front of the method call (the = sign) you are commenting the whole ruby code, hence the interpreter has no problem with it. yeah i am suspecting it is either: %= whatever % changed to % concat(whatever) % or changed to % output_buffer whatever % so if it is %= #comment % it becomes % concat( #comment ) % or % output_buffer #comment % the first one fails because it comments out the ) as well. the second one fails because it is missing something for the operator. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] library for URL parameters adding, removing, or replacing?
i think PHP doesn't have such simple functions yet... does Ruby have it? if in PHP, when we add a param to the URL $redirectURL = $printPageURL . ?mode=1; it works if $printPageURL is http://www.somesite.com/print.php;, but if $printPageURL is changed in the global file to http://www.somesite.com/print.php?newUser=1;, then the URL becomes badly formed. If the project has 300 files and there are 30 files that append param this way, we need to change all 30 files. the same if we append using mode=1 and $printPageURL changes from http://www.somesite.com/print.php?new=1; to http://www.somesite.com/print.php;, then the URL is also badly formed. is there a library in Ruby/Rails that will automatically handle the ? and , and even checks that existing param exists already and removed that one because it will be replaced by the later one and it is not good if the URL keeps on growing longer? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] do we usually use Iconv to do translate to various encodings
I wonder if we usually use Iconv to translate to various encoding? For example: Iconv.conv(UTF-8, BIG-5, content) or Iconv.conv(UTF-8, CP950, content) or do we usually use other packages? One reason is that BIG-5 can cause an exception while CP950 won't on some content, and both of them are supposed to be Tradtional Chinese encoding. by the way, iconv -l on the shell will give names of all encodings. Are they supposed to be usable by the ruby Iconv library? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Colin Law wrote: Have you made the suggested change to count the words in the document first then update the db, so that you are not updating each record in the database many times (presumably hundreds of times for common words)? This will change the number of db accesses from the total number of words in the document to the number of unique words in the document. yes, so right now i first tally up the count by a Hash, and then at the end, write all the data to the table. it is strange that writing all this data take a minute or so... because the final db is only 2.5MB, and that if i write all the data to a flat file, i think it is done in 2 seconds. so right now, i want to find out 1) can i tell sqlite3 not to write to the db every time i add a record (a row), but to do it all in memory and then finally, write to the table once at the end. 2) use memCache to do it. 3) some one at stackoverflow.com suggested using AR:Extensions http://stackoverflow.com/questions/843524/updating-the-db-6000-times-will-take-few-minutes but i just want to use the most basic way to do it... such as by turning off the force-write of sqlite3 -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Gary Doades wrote: If you have made the change to count up words first and then *insert* all the (word,count) records into the database in a *single* transaction then it ought to take less than a second. I would expect that the total number of (word,count) records is in the order or hundreds or perhaps a thousand or so? Any decent DB ought to insert that in under a second as a *single* transaction. If it is still taking minutes then you are probably not doing the above somehow. I think in that case you need to post your code again so we can see what it is doing now. i was doing it like this: all_phrases = frequencies.keys Phrase.transaction do all_phrases.each do |phrase| recordPhrase = Phrase.new(:s = phrase, :frequency = frequencies[phrase], :length = lengths[phrase]) recordPhrase.save end end i am using Phrase instead of Word... but it is the same thing... all_phrases.length is about 34000 for all data... it would run for at least a minute... that's kind of weird... -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Jian Lin wrote: i was doing it like this: all_phrases = frequencies.keys Phrase.transaction do all_phrases.each do |phrase| recordPhrase = Phrase.new(:s = phrase, :frequency = frequencies[phrase], :length = lengths[phrase]) recordPhrase.save end end by the way, the table has indexes on all fields: s, frequency, and length. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Gary Doades wrote: I'm not sure how you get 34000 records from 6000 words. Surely you should get less not more. it would run for at least a minute... that's kind of weird... Are you sure it is just the above code that is taking a minute and not the bit of code that counts the words? What hardware is this on exactly? it is 34000 records because it is actually count up phrases instead of words... for example, a quick brown fox jumps over the lazy dog i will actually count phrases such as a quick a quick brown a quick brown fox etc... so the final result is 34000 entry hashes, mapping to frequencies and word counts. the hardware should be pretty good... it is the HP TouchSmart IQ804... with a Core 2 Duo and hard drive ST3320820AS which is 7200rpm, 8MB buffer. hm... makes me wonder if the db is just 4MB, how come the hard drive buffer 8MB didn't totally handled it in its RAM and be super fast. did it actually force write to the physical disc? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Michael Schuerig wrote: On Sunday 10 May 2009, Jian Lin wrote: end Consider Phrase.transaction do frequencies.each do |phrase, freq| Phrase.create!(:s = phrase, :frequency = freq) end end Hash#each passes keys and values to your block and avoids unnecessary lookups. My snippet above doesn't take into account your :length = lengths[phrase] and that is as it should be. Presumably, lengths[phrase] == phrase.length. Then class Phrase ActiveRecord::Base attr_protected :length ... def s=(value) self.length = value.length end end would be much cleaner code because it puts responsibility for setting the length attribute where it belongs. i changed it to time_start = Time.now Phrase.transaction do all_phrases.each do |phrase| recordPhrase = Phrase.create!(:s = phrase, :frequency = frequencies[phrase], :length = lengths[phrase]) end end p took , Time.now - time_start, seconds to finish but it is still the same: it took 75 seconds... i wanted the length, which is the count of word because in the future i might want to do query such as select * where length 3 and so if i count the word by getting s first, then it will be really slow won't it? if length is stored and indexed, then length 3 can be super fast? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Gary Doades wrote: Jian Lin wrote: but it is still the same: it took 75 seconds... That's because it's still really the same code! i wanted the length, which is the count of word because in the future i might want to do query such as select * where length 3 and so if i count the word by getting s first, then it will be really slow won't it? if length is stored and indexed, then length 3 can be super fast? Just because it has an index on it doesn't automatically make it super fast. It depends largely on the selectivity of the length field. I suspect that most of your phrases are larger than 3 characters and so such a query will result in a full table scan anyway. In that case making the table smaller by leaving out the length may actually make it faster. However, selecting all the phrases where length 5 would almost certainly use the index and make it faster. Only you know what you are likely to do in general here so you need to decide (and test) whether it is better to have the index and length column or not. You can always do select * from phrases where length(s) 3 or something like. Are you sure your overall run time is not limited by CPU rather than IO? How much CPU time is used to run your code? oh sorry i should have clarified... the length is actually the count of words... so length 3 means 3 words at least. or i might do a query that is word 5 or 7... so will having an column and an index make it fast if i do query such as length 7? i intend for example to get back only 5% or 3% of all records so the index might make it fast. by the way, the 75 second is the time from the moment the Phrase.transaction do to the end of it... so... i think during that time it is mostly IO time... let me actually write up a test case with some dummy data to simulate it so that every one is on the same ground... -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
ok, the following code with 6000 records insert will take 13.3 seconds to finish (just for the db portion). if i change 6000 to 3 then it will take 67 seconds. it is being run using ruby script/runner foo.rb code: srand(123) frequencies = {} lengths = {} 6000.times do phrase = (65+rand(26)).chr + #{rand(100_000_000)}; frequencies[phrase] = rand(20); lengths[phrase] = rand(10); end #p frequencies all_phrases = frequencies.keys p Starting inserting records time_start = Time.now Phrase.transaction do all_phrases.each do |phrase| recordPhrase = Phrase.create(:s = phrase, :frequency = frequencies[phrase], :length = lengths[phrase]) end end p took #{Time.now - time_start} seconds to finish p Phrase.count the scheme.rb for the table is create_table phrases, :force = true do |t| t.string s t.integer frequency t.integer length t.datetime created_at t.datetime updated_at end add_index phrases, [frequency], :name = index_phrases_on_frequency add_index phrases, [length], :name = index_phrases_on_length add_index phrases, [s], :name = index_phrases_on_s -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Gary Doades wrote: Jian Lin wrote: ok, the following code with 6000 records insert will take 13.3 seconds to finish (just for the db portion). if i change 6000 to 3 then it will take 67 seconds. OK, I created the table and the index and ran your code for 3 records, but I wrapped the database part in a Benchmark.measure{} Using MySQL: For 3 inserts with no indexes: Starting inserting records 31.996000 0.639000 32.635000 ( 35.356000) 3 For 3 inserts with all indexes: Starting inserting records 32.795000 0.982000 33.777000 ( 37.103000) 3 That's 33 seconds of CPU time with 37 seconds elapsed on a quad core 2.4 GHz with a Seagate Barracuda SATA drive with 32MB cache. As you can see, it's pretty much all in CPU time The result was essentially the same in Postgres and MS SQL server! So you can forget about the database itself. None of the database engines were unduly taxed by the test. Just for fun I changed the program to output the data as SQL INSERT statements and then run that (with 3 inserts wrapped in a transaction) against MySQL. Imported in 1.2 seconds!! I Don't know if it is the hash lookup code or ActiveRecord that is gobbling up the time, but it certainly isn't the database. You'll need to tinker with, or better profile your code to find out what is sucking up the time. yeah that's what i was going to say... the line Phrase.transaction do didn't cause any transaction statement to show up in the development.log so is it suppose to have begin a transaction? so the 1.2 second result you have, is by collecting all those INSERT statements and then wrap them in a begin transaction and commit and it is 1.2 seconds... I wonder then, can't this be achieved in ActiveRecord? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Gary Doades wrote: Starting inserting records 31.996000 0.639000 32.635000 ( 35.356000) 3 For 3 inserts with all indexes: Starting inserting records 32.795000 0.982000 33.777000 ( 37.103000) 3 I Don't know if it is the hash lookup code or ActiveRecord that is gobbling up the time, but it certainly isn't the database. by the way... interesting to find out the CPU time is so much... i thought this code is I/O bound at first... by the way I am using Rails 2.3.2, Ruby 1.8.6 patchlevel 287... on Windows 7. hm... the Hash look up time should be really small... for example, if i just write all data to a text file, it should be really fast... it might be ActiveRecord, although I though ActiveRecord merely translate the method into a SQL statement and so shouldn't be so CPU intensive. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Gary Doades wrote: Aha It looks like ActiveRecord has an enormous overhead in creating/saving records. If you change the inserts to this puts Benchmark.measure { Phrase.transaction do all_phrases.each do |phrase| Phrase.connection.execute(insert into phrases(s,frequency,length) values('#{phrase}',#{frequencies[phrase]},#{lengths[phrase]})) end end } you get this: Starting inserting records 1.123000 0.686000 1.809000 ( 5.096000) 3 Which is exactly what you want I think :) i was googling for ActiveRecord transaction and got this page http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html where it says: Save and destroy are automatically wrapped in a transaction so i think create is also invoking a save... do you think so? if it is then it is making it a transaction. that's why it is so slow... it cannot be lots of record creations in a single transaction, or maybe there is a method and we don't know yet (maybe a method is using ar:extensions, or why not have a standard activerecord mechanism to do hugh updates/inserts, i wonder) -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Jian Lin wrote: Save and destroy are automatically wrapped in a transaction so i think create is also invoking a save... i just read from Learning Rails the book (p.50 if remembered correctly) that create is 3 operations in one: it has a new, an assignment of values, and a save, so create involves a save, and therefore is in a transaction by itself. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Frederick Cheung wrote: On May 10, 10:41�am, Jian Lin rails-mailing-l...@andreas-s.net wrote: it actually force write to the physical disc? It's never that simple (and yes under the appropriate circumstances the drive is supposed to flush to the actual disk). For example there's a constant amount of overhead with each query: network latency etc. not a huge amount (probably less than a millisecond), but multiply that by 34000 and it will add up. If you really need to manipulate this much data you'd be well advised to do the inserts in bulk. so how to do inserts in bulk? by using Phrase.connection.execute(insert into phrases(s,frequency,length) values('#{phrase}',#{frequencies[phrase]},#{lengths[phrase]})) ? or by ar-extensions? can ActiveRecord have a mode for saving without being in a transaction, or can ActiveRecord has some standard method of doing bulk inserts? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Michael Schuerig wrote: On Sunday 10 May 2009, Jian Lin wrote: so how to do inserts in bulk? by using Phrase.connection.execute(insert into phrases(s,frequency,length) values('#{phrase}',#{frequencies[phrase]},#{lengths[phrase]})) You might be using the wrong tool and you might be reinventing existing solutions. Did you have a look at existing text mining tools/frameworks in Ruby as well as other languages? i want to do this project and also at the same time let me have a chance to learn to use the ActiveRecord... perhaps i can use some kind of traverse tool to walk the internet too... something that can start at a page and then walk down all page by a level of 1 or 2 or any number. it won't be so hard to write except sometimes the baseurl is used and it is more processing than using absolute url. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] % % is not exactly the same as ?php ?
it seems that % % is not exactly the same as ?php ? in which, PHP's ?php echo something ? will add to the output but ERB's % puts something % will not? Does someone know if JSP and ASP behave like ERB or PHP and can make a summary of their likes and differences? Thank you. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] does somebody use XCode on Mac for RoR instead of TextMate?
does somebody use XCode on Mac for RoR instead of TextMate? I wonder how is it compared to TextMate... TextMate uses the default font of Monaco... the Xcode screenshot on Wikipedia uses Courier... I wonder if Xcode looks as good as TextMate when the font is changed to Monaco as well? Thank you. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: % % is not exactly the same as ?php ?
Jian Lin wrote: it seems that % % is not exactly the same as ?php ? in which, PHP's ?php echo something ? will add to the output but ERB's % puts something % will not? actually, i found that % puts 123 % prints 123 to the stdout. so the shell that is running script/server will see 123... but the 123 is not part of the webpage generated. Is there a way or option to include that 123 as part of the generated HTML? thanks. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: does somebody use XCode on Mac for RoR instead of TextMate?
Conrad Taylor wrote: Jian, I use Xcode sometimes when I'm doing MacRuby development with Monaco font and a size of 14pt. Xcode allows you to change the font size as do most applications that allow you enter text. so there is no need to spend 39 euro to buy TextMate? I was wondering if other editors can open up a folder and put it on the left panel like TextMate does... that's kind of handy for RoR development. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: % % is not exactly the same as ?php ?
Rob Lacey wrote: %= blah % is what you are looking for actually... sometimes i want to output multiple things inside of % %, or put everything inside a loop and inside a % %, so that's why the question of % puts 123 % -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: does somebody use XCode on Mac for RoR instead of TextM
by the way, i was using Notepad++ a lot on the PC, and almost want to just use that for anything... but it seems to have no way to open up a folder like TextMate does... so it is a bit inconvenient for RoR development. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: % % is not exactly the same as ?php ?
Alberto Santini wrote: Jian Lin wrote: actually... sometimes i want to output multiple things inside of % %, or put everything inside a loop and inside a % %, so that's why the question of % puts 123 % I think you should use something like: % for x in y do % %= #{x.z}, #{x.a} % % end % so for example... if i have the code % begin t = '' s = Iconv.conv(UTF-32, UTF-8, some_utf8_string) (s.length / 4).times do |i| b3 = s[i*4 + 2] b4 = s[i*4 + 3] t += (#x + %02X % b3) + (%02X % b4) + ; end rescue = details t = exception + details end % %= t % then if i don't want to concat the output into t first... then would it be a bit messy to use % begin t = '' s = Iconv.conv(UTF-32, UTF-8, some_utf8_string) (s.length / 4).times do |i| b3 = s[i*4 + 2] b4 = s[i*4 + 3] % %= (#x + %02X % b3) + (%02X % b4) + ; % % end rescue = details % %= exception + details % % end % -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] want to put processing logic in Controller but no strip_tags
I want to put the processing logic in the controller... and it has a strip_tags call... and the controller portion will say the function doesn't exist. so is there a way to call strip_tags from the controller? (instead of from view). -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] updating the db 6000 times will take few minutes ?
i am writing a test program for ActiveRecord, and it reads a document which is like 6000 words long. And then i just tally up the words by recordWord = Word.find_by_s(word); if (recordWord.nil?) recordWord = Word.new recordWord.s = word end if recordWord.count.nil? recordWord.count = 1 else recordWord.count += 1 end recordWord.save and so this part loops for 6000 times... and it takes a few minutes to run at least using sqlite3. Is it normal? I was expecting it could run within a couple seconds... can MySQL speed it up a lot? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: How many RoR engineers use Mac / Linux / Windows?
is it true that surveymonkey.com won't show the survey answers to general users who voted? (unless the survey creator is not using a basic account)... so the result so far is: Mac: 10 Linux:9 Windows: 4 Other:1 -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Gary Doades wrote: I'm glad you said it was a test because it wouldn't be nice to do that for real. It looks like you've got at least 12000 transactions in there (select + update). Any indexes would make it worse. I'm guessing that this would take around 5 minutes on decent single disk PC hardware. No database engine (even oracle) is going to do that in 2 seconds on a standard PC with a single sata/ide hard disk. You're asking for 6000 read/write operations per second. You'll need some mighty big hardware to do that! If you did the whole thing in a single transaction you might get it to go quite a bit faster. will record.save automatically make it a transaction? so how do i make it into 1 transaction? I can't make it a hash or an array of records and at the end, do a loop of record.save too? because each will be a transaction... ? what about using memcache? the db seems like was about 45MB when i run 6000 words test on a few pages... so memcache of 64MB... maybe everything will happen in RAM and it can be really fast? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Colin Law wrote: Would not the index make the lookup faster but the write slower? Is it that the cacheing would mean that the lookup would be pretty quick anyway, even without an index? Colin 2009/5/9 Gary Doades g...@gpdnet.co.uk yeah, seems like the search will be a lot faster with the index... i was also thinking of using production mode to run it, since the development mode will write all the SQL log and slow down the operation... -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Colin Law wrote: Is this a test or a real requirement? If it is a real requirement then count the words in memory first and then update the db so each record is only written once. Colin 2009/5/9 Jian Lin rails-mailing-l...@andreas-s.net it is a real requirement... so how do i update the db at the end in 1 operation? thanks. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
great... will try it out now. actually, i was thinking, that the computer sometimes has 1GB free RAM or 3GB free RAM (of the 4GB of RAM). how come the OS doesn't automatically create a cache for the 45MB db file? If the OS creates the cache, everything happens in memory, and it should be quite fast. Is it true that sqlite3 actually flush the data into the hard drive? but at least for the searching part, can it still happen just in RAM? Can't MySQL or Sqlite3 actually have a mode so that the db can be cached in RAM as much as possible? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Gary Doades wrote: Jian Lin wrote: in RAM as much as possible? The database can be cached in ram by most database engines. However, most database engines will also make sure that every transaction (insert, update, delete) is committed to disk by forcing a write to the physical disk for *every* transaction. If the database engine doesn't do this you risk losing part or all of your database if some kind of failure happens part way though your updates. If you don't care if you lose part or all of your database, most database engines also have a setting for this. so i re-ran the test and it worked quite quickly... down to 1 minute or so instead of 30 minutes... (for several pages)... and the db size is only 2.5MB (i created another rails project to start anew). So if we are just write scripts, and running with script/runner test.rb, how can we turn the force write feature of the sqlite3 off? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: updating the db 6000 times will take few minutes ?
Phlip wrote: Jian Lin wrote: so i re-ran the test and it worked quite quickly... down to 1 minute or so instead of 30 minutes... (for several pages)... and the db size is only 2.5MB (i created another rails project to start anew). So if we are just write scripts, and running with script/runner test.rb, how can we turn the force write feature of the sqlite3 off? Are you running inside a transaction? sqlite3 in transaction mode is super-fast... (Jumping into the thread late, why should a test push 6 000 records? Such a test is not exactly a unit test, and alternate strategies should work better.) i tried both record.save and record.save! and both needed a few minutes at the end of the program to write the data to the db... i am writing a program to tally up the common word or phrases (say, either in English or Chinese) that appears often. So for example, at the end of the program (i used ruby script/runner check.rb to run it using Ruby with ActiveRecored support), when the results are in, it may be a table of 6000 keys and 6000 frequency counts. So I need to write the data into the db. That's it. Wonder why it takes a few minutes and how to make it just be a few seconds. If I just write the results to a flat text file using CSV format, it should take no more than a few seconds, i think. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---