Re: [Rails] How do we get the End of Line date for the gems which we are using Ruby on Rails?
Quoting Colin Law : > On 10 October 2012 10:39, RoR Uk wrote: > > Hi All, > > > > I want to know the EOL date for the below gems for ROR. Can anyone help me > > how to find the EOL dates > > What do you mean by EOL date (presumably End Of Line, but what do you > mean by that)? > End Of Life - usually defined when there is no more support. HTH, Jeffrey -- 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 https://groups.google.com/groups/opt_out.
Re: [Rails] How to escape a forward slash with gsub, also does interpolation work with gsub?
Quoting S Ahmed : > I am trying this: > > I want to replace all the text in between java comments: > > /* start */ > replace this text here > /* end */ > > > I'm trying: > > text.gsub(//* start */(.*)/* end *//im, replace_with) > > But i'm getting errors relating to expecting keyword_end. > > How should I be escaping /* and */ ? Yes, text.gsub(/\/\* start \*\/(.*)\/\* end \*\//im, replace_with) Slightly simpler text.gsub(%r{/\* start \*/(.*)/\* end \*/}im, replace_with) > > Also, does string interpolation work in gsub regex? Say I had variables > like: > > start_tag = "/* start */" > end_tag = "/* end */" > > I want to do: > > text.gsub("#{start_tag}(.*)#{end_tag}", replace_with) > gsub takes regex, not strings text.gsub(/#{start_tag}(.*)#{end_tag}/, replace_with) Special characters do need to be escaped in start_tag and end_tag, but in this case only the asterisks, not the slashes. HTH, Jeffrey -- 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 https://groups.google.com/groups/opt_out.
Re: [Rails] Bundle Install ERROR: ERROR: Failed to build gem native extension.
You need to install the BZ compression library, including it's header files, usually in libbz2-dev or libbz2-devel. HTH, Jeffrey Quoting Tak G. : > Hello, > > I'm trying to setup postgreSQL onto rails on linux and when I type > bundle install this is the error that i get. I guess its not finding > the files > > Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native > extension. > > /home/taka/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb > checking for bzlib.h... no > checking for BZ2_bzWriteOpen() in -lbz2... no > *** extconf.rb failed *** > Could not create Makefile due to some reason, probably lack of > necessary libraries and/or headers. Check the mkmf.log file for more > details. You may need configuration options. > > Provided configuration options: > --with-opt-dir > --with-opt-include > --without-opt-include=${opt-dir}/include > --with-opt-lib > --without-opt-lib=${opt-dir}/lib > --with-make-prog > --without-make-prog > --srcdir=. > --curdir > --ruby=/home/taka/.rvm/rubies/ruby-1.9.3-p194/bin/ruby > --with-bz2-dir > --without-bz2-dir > --with-bz2-include > --without-bz2-include=${bz2-dir}/include > --with-bz2-lib > --without-bz2-lib=${bz2-dir}/lib > --with-bz2lib > --without-bz2lib > libbz2 not found, maybe try manually specifying --with-bz2-dir to find > it? > > > Gem files will remain installed in > /home/taka/.rvm/gems/ruby-1.9.3-p194/gems/bzip2-ruby-0.2.7 for > inspection. > Results logged to > /home/taka/.rvm/gems/ruby-1.9.3-p194/gems/bzip2-ruby-0.2.7/ext/gem_make.out > An error occurred while installing bzip2-ruby (0.2.7), and Bundler > cannot continue. > Make sure that `gem install bzip2-ruby -v '0.2.7'` succeeds before > bundling. > > -- > 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 https://groups.google.com/groups/opt_out. > > -- 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 https://groups.google.com/groups/opt_out.
Re: [Rails] Using one model's attribute in another model's method
Quoting sacshu : > I'm slightly new at Rails, so any help would be appreciated! > > I have two models that have no association with each other (but they would > probably be many-to-many). One is called 'Course' and contains seed data of > Golf Courses. The other is called 'Player' and contains user entered > information. Ultimately, I want to show a table in my view that displays > all the golf courses appropriate for the player, based upon some > calculations I'm doing in my Player model. However, I need to utilize some > of the attributes from the Course model in my calculations. > > Right now, all my methods are in the Player model, so I'm doing something > like this but am getting an 'undefined method 'Course' error. What am I > missing? > > Player.rb > class Model < ActiveRecord::Base > attr_accessible :attr_1, :attr_2, ...etc > > def handicap_differences > Course.handicap (This is what I'm using to call the Course handicap, > but it's not working out) - player_handicap + some more math > end > end > Course.handicap() is a class method. I.e., not specific to any course instance. And you will have fewer problems if the class name matches the file name. E.g. in player.rb (all lower case). class Player < ActiveRecord::Base ... What is the class name in course.rb? Is it also Model? It should be Course. Jeffrey -- 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 https://groups.google.com/groups/opt_out.
Re: [Rails] RoR App - Location Search Gem/Algorithm?
Quoting William Moss : > Hi guys > > Just a question... I need some advice > > I am looking to put together a RoR app to interface with an iPhone app > > The iPhone app will be like a 'find the nearest' app. When the user runs > it, it will take the user's location, send a JSON request to the RoR app > running on a remote server with the location in the querystring > > The RoR app should then send back a list of locations for a particular > location for the iPhone app to display on the map. > > Is there any good gems that might help with this? I already have the > locations stored in the database along with and address, and can convert > the address into lat/long using geocoding. > > The part I am stuck about is an algorithm to search the database for the > 'nearest' locations given a particular lat/long. > PostgreSQL with the PostGIS can do this. Look at https://github.com/chip-rosenthal/findit. It is a Sinatra app, not Rails but should give you working code to learn from. HTH, Jeffrey -- 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 https://groups.google.com/groups/opt_out.
Re: [Rails] Commands of creating new app. are different.
Quoting Rubyist Rohit : > I am following "Head First Rails" to learn Rails Web Application > Development. > [snipped] You need to match major versions and preferably minor version of Rails. From the snipped part of your e-mail, it's clear that "Head First Rails" was written for Rails 2, which is no longer supported. My suggestion is find a tutorial written for Rails 3, preferably Rails 3.2 (the current version). HTH, Jeffrey -- 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 https://groups.google.com/groups/opt_out.
Re: [Rails] Environments
Quoting BeagleBen : > Hello all > > I am returning to rails after a moving in with asp.net mvc for a while, I > have setup rails on a centos server with passenger, I have set the rails > environment as production within my httpd config, when I do rake about it > show the environment as development, Please can anyone advise what I have > missed. > You are running production in your webserver (presumably on port 80) and development on the command line. This is normal. They are separate contexts. The httpd config only applies to the Web server, not a terminal session. If you would start Webrick or other Rails server from the command line, it would run the development environment on port 3000. If you want to run in production mode from the command line, type "export RAILS_ENV=production" in bash or the equivalent in other shells (e.g. "RAILS_ENV=production; export RAILS_ENV" in sh). HTH, Jeffrey -- 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.
Re: [Rails] rails block in js.erb ?
Quoting Erwin : > I am trying to run a bloc in a js.erb script , but I don't get ir ... > debugger show that the test is true, so it should run .. > > <% if (params[:blog_page].to_i > 0) do %> > >alert("should redisplay the dashboard page"); >window.location.href = <%= backoffice_url %>; >location.reload(); >$('#blog-info').html( '<%= escape_javascript(render :partial => > "backoffice/dashboards/lists/blog_info") %>'); >$('#blogInfo').tab('show'); > > <% end %> > > what's wring with tho writing ?? > The 'do' after the 'if' condition is incorrect. Remove it. HTH, Jeffrey -- 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.
Re: [Rails] error in "each" method in following code.
Cut it down to the minimun necessary to show the problem. There are several each calls here. Jeffrey Quoting Prajwal B. : > require 'rubygems' > require 'nokogiri' > require 'sqlite3' > > FIELD_NAMES = [['selectcity', 'VARCHAR'],['match', 'VARCHAR'], > ['phone_no', 'NUMERIC'], ['name', 'VARCHAR'],['address', 'VARCHAR'] ] > > TABLE_DIV_ID = "#dgrSearch" > OFILE = File.open('data-hold/tel-directory.txt', 'w') > OFILE.puts( FIELD_NAMES.map{|f| f[0]}.join("\t") ) > > DBNAME = "data-hold/tel-directory.sqlite" > File.delete(DBNAME) if File.exists?DBNAME > DB = SQLite3::Database.new( DBNAME ) > > TABLE_NAME = "telephone_records" > DB_INSERT_STATEMENT = "INSERT into #{TABLE_NAME} values > (#{FIELD_NAMES.map{'?'}.join(',')})" > > DB.execute "CREATE TABLE #{TABLE_NAME}(#{FIELD_NAMES.map{|f| "`#{f[0]}` > #{f[1]}"}.join(', ')});" > FIELD_NAMES.each do |fn| > DB.execute "CREATE INDEX #{fn[2]} ON #{TABLE_NAME}(#{fn[0]})" unless > fn[2].nil? > end > > Dir.glob("data-hold/pages/*.html").reject{|f| f =~ /All match/}.each do > |fname| >meta_info = File.basename(fname, '.html').split('--') >page = Nokogiri::HTML(open(fname)) > > page.css("#{TABLE_DIV_ID} tr")[1..-2].each do |tr| > data_tds = tr.css('td').map{ |td| > td.text.gsub(/[$,](?=\d)/, '').gsub(/\302\240|\s/, ' ').strip > } > > data_row = meta_info + data_tds > OFILE.puts( data_row.join("\t")) > DB.execute(DB_INSERT_STATEMENT, data_row) > > end > end > > OFILE.close > > -- > 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. > -- 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.
Re: [Rails] rake error
Quoting Meow san : > /usr/bin/rake:9:in `require': no such file to load -- rubygems > (LoadError) > from /usr/bin/rake:9 > > I got this error when following an online guide in rails, the command > I had to type in was # rake db:create.. after I typed in the command I > got the above error. It's almost 2 days that I'm searching for a > solution to this. But in vain, > Is rubygems installed? At the command line, type: gem list --local rubygems If nothing listed, type "gem install rubygems", preferably as root. HTH, Jeffrey -- 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.
Re: [Rails] Upgrading to Rails 3
Quoting Gurdipe Dosanjh : > Hi All, > > Thanks to everyone for the great updates on how to upgrade to Rails 3. > > What are the technical and business benefits of upgrading to the latest > versions of Ruby an Ruby on Rails. > > The application we have written is still on Ruby version 1.8.7 and Ruby on > Rails version 2.3.5 There are no bug or security fixes for 2.x. Nor if I understand the policy correctly, 3.0.x. I'd suggest moving to 2.3.14 first before jumping to 3.x. Jeffrey -- 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.
Re: [Rails] Agile Web Development 4th ed. - Can't mass assign.error
Quoting Lucas J. : > I am new to Ruby and to Rails (using Ruby 1.9.3 and Rails 3.2.3) so I > picked up the Agile Web Development book and have been working through > it (apologies if this isn't the correct place for this question but the > pragprog forums don't seem to work for me). I am currently working > through the book and have reached the point where I am adding > functionality to an "Add to Cart" button. Here is the code that was > provided for the 'create' method in the line_item_controller: > > def create > > @cart = current_cart > product = Product.find(params[:product_id]) > @line_item = @cart.line_items.build(product: product) > > ... > > end > > This results in the following error when I click "Add to Cart" > > Can't mass-assign protected attributes: product > > Can anyone shed some light on what is going on here (my search-fu has > failed me)? The only way that I have been able to get this to work is > by changing the code (starting at @line_item) to: > > @line_item = @cart.line_items.build > @line_item.product = product > > Is this correct or is it just a band-aid fix that may cause issues going > forward? > This is a correct way to do it now. And probably the best way to move forward with the tutorial right now. The newest releases of Rails have made mass-assign protection the default. Without it you have a security risk. You can learn more by Googling "Rails mass assign". Save it for after you complete the book. HTH, Jeffrey -- 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.
Re: [Rails] Re: Upgrading to Rails 3
Quoting Gurdipe Dosanjh : > Hi All, > > Re: Upgrading to Rails 3 > > I am working on a rails application I need to upgrade to the latest version > of Ruby and Ruby on Rails. > > It is currently using: > > Ruby version 1.8.7 and > Ruby on Rails version 2.3.5 > > Is there any information, tutorial, guides etc. I can follow > > Any help would be greatly appreciated > In addition to the other advice, overriding ActiveRecord callbacks was deprecated in 2.3.8. So replace def before_save # whatever end with: before_save :whatever private def whatever # whatever end HTH, Jeffrey -- 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.
Re: [Rails] Re: Pessimistic locking locks the entire table?
This is similar to a application I am working on. In my case, all updates to the database, with one exception, can be done atomically. For examples, use SQL UPDATE to increment a field rather than read with pure Rails/ActiveRecord, increment model instance, and write. The one exception is adding new instances of model with several assocations. My solution is that all problematic actions are done with ONE Resque worker that runs forever. The cron jobs are Ruby (not Rails) programs that enqueue a task to the Resque worker. This has worked very well. I was pleasantly surprised how easy it went together. The one con is that Resque workers are not good about reporting exceptions and other problems and in the development environment they reload properly after most, but not all changes. So in the development environment if there are problems or I am making big and deep changes, I will stop the Resque worker and run the problematic code with script/runner or whatever the Rails 3 equivalent is. HTH, Jeffrey Quoting PierreW : > I don't know if using pessimistic locking is the best way to do it, > but here is why I used this: > > - every X hours a demon runs and updates records > - thing is, this demon "action" can last Y with Y > X > > So there is a risk that two instances of the demon try to update the > same record. So each demon needs to acquire the lock before they can > do anything on a given record. > > I guess an alternative could be to try and make sure that a demon only > starts if the previous one has finished but this was not an option in > my case. > > Adding an index was actually fairly easy. > > On Apr 4, 12:37 am, Robert Walker wrote: > > wam r. wrote in post #1054714: > > > > > Hi guys, > > > > > I must be missing something obvious with pessimistic locking. Here is > > > what I do (Rails 2.3, mySQL): > > > > So is there a reasonable use case for pessimistic locking on a web > > application? That seems insane to me. > > > > -- > > Posted viahttp://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. > -- 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.
Re: [Rails] Invoking one controller's methods from other controller
Quoting Pallav_bfs : > I have a controller (employee) with it's model and view. Now I need to > write another controller (emp) which would not have any model or view. > This emp controller should be able to invoke all the methods of > employee controller.And eventually be able to represent all the > relevant information. > > I have also a dependent controller of 'employee' which is 'account' . > I have set up routes as per that. > # in routes.rb > - > resources :employees do > resources :accounts > end > > and, resources :emp, :as =>"employees" do >resources :acc , :as=>"accounts" > end > -- > POST on /emp/ would be as good as a POST on /employees/ > or GET on /emp/1/edit should work as GET on /employees/1/edit > or GET on /emp/1/acc should be equivalent toGET on /employees/1/ > accounts > > I was thinking how to write the emp controller.Please help. > You've said what is the same between emp and employee. So what is different between emp and employee? In general, you cannot call the instance methods of one class for another class, only class methods. Depending on what you are trying to do, emp can inherit from employee or there is only the employee controller and routes map the emp requests onto the employer controller. HTH, Jeffrey -- 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.
Re: [Rails] paginate a table
Quoting Rogelio A. RogeX : > Hi, I am try paginate a table with plugin WillPaginate, but according to > me I can only paginate as following: > > //make a query, > data = Model.paginate(:per_page => 5).. > > //Show paginate > <%= WillPaginate @data% > > And I need paginate so: > > obj1 = Model1.find(). > obj2 = Model2.find(). > > obj3 = obj1-obj2 > > <% WillPaginate obj3 %> > > Its possible use the plugin for paginate a object in memory?? > Look at the examples near the bottom of this page: https://github.com/mislav/will_paginate/wiki HTH, Jeffrey -- 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.
Re: [Rails] 110.years.ago.to_datetime returns wrong date
Quoting John Merlino : > > I run this in console: > > >> 110.years.ago.to_datetime > => Fri, 14 Mar 1902 01:20:12 + > > Today is the 13th of march. So why is it returning 14th? > Time zones. Notice the + at the end. You are in the Pacific time zone according to the headers in your e-mail (assuming the list server hasn't mangled them). So Fri, 14 Mar 1902 01:20:12 + is Thu, 13 Mar 1902 18:20:12 -0700 Probably your Rails in configured to use UTC as the default timezone. $ cd config/ $ grep UTC * environment.rb: config.time_zone = 'UTC' environment.rb~: config.time_zone = 'UTC' HTH, Jeffrey -- 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.
Re: [Rails] SOT: HTML question about clickable area
Quoting Dev Guy : > On Sun, Feb 26, 2012 at 9:08 PM, Jeffrey L. Taylor > wrote: > > On the development version of my Web app, the clickable area of some anchors > > is the text area and the padding (margin and border are both zero). On the > > production version, only the padding is clickable. Any hints on how to > > track > > down the difference that makes a difference would be appreciated. > > [snip] > > With firefox you could use firebug to discover how these properties > are getting set. > The style and layout as reported by Firebug are identical. The HTML, at least right around the problematic section is identical. And the problem is not perfectly reproducible. Sometimes it's there, sometimes not. Firefox was not restarted between non-working and working sessions. Sigh. Jeffrey -- 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] SOT: HTML question about clickable area
On the development version of my Web app, the clickable area of some anchors is the text area and the padding (margin and border are both zero). On the production version, only the padding is clickable. Any hints on how to track down the difference that makes a difference would be appreciated. TIA, Jeffrey -- 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.
Re: [Rails] Query on db with mysql
Quoting Paul Na : > Hi all, > > > I have a host that allows ssh access but only on the main account. I was > just wondering can you setup the db without using the command line e.g > db:migrate generate etc as on my main account its fine but if i setup > other sites i will have to pay $10/£6 to activate ssh. > Cannot you ssh into the main account and then change user to the other account? My Amazon cloud account is like this. Only one normal user account is allowed to ssh in. I then change to the root and Web server accounts as needed. HTH, Jeffrey -- 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.
Re: [Rails] Issues with template encoding (invalid byte sequence in UTF-8):
The template is likely UTF-8, but the information from the database, e.g. entry[:original_url] is likely ASCII-8BIT if you are using MySQL and the mysql adapter, assuming your tables are UTF-8. Try using the mysql2 adapter instead. IIRC, install the mysql2 gem and change all 'adapter: mysql' in config/database.yml to 'adapter: mysql2'. HTH, Jeffrey Quoting Mex Noob Yes : > Well i have tried to find the answer by myself and i had no luck at all, > so here it is: > > i have followed all the tips i have found here and there, putting > <% # coding: UTF-8 %> > using encode and force_encoding > even trying some wacky regex i came up with (which of course was a dumb > idea) > > i am using ruby 1.9.2p290 and Rails 3.0.3 > > i have no clue at all what is wrong > > the crazy part of this is that the line where the error happens > is an URL... > > > ActionView::Template::Error (invalid byte sequence in UTF-8): > 52: " > title="Direccion de la informacion."> > 53:URL > 54: > 55: target="_blank" title="<%= CGI.unescape( entry[:original_url] ) > %>">Abrir en nuevo tab. > 56: > 57: > 58: > app/views/main/results.html.erb:55:in `block (2 levels) in > _app_views_main_results_html_erb__4329752108549495342_44926400_4357034463775245520' > app/views/main/results.html.erb:33:in `block in > _app_views_main_results_html_erb__4329752108549495342_44926400_4357034463775245520' > app/views/main/results.html.erb:23:in `each' > app/views/main/results.html.erb:23:in > `_app_views_main_results_html_erb__4329752108549495342_44926400_4357034463775245520' > > in advance thank you very much for your 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. > -- 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.
Re: [Rails] Re: Re: Re: Encoding error
Quoting Felipe Pieretti Umpierre : > Jeffrey L. Taylor wrote in post #1044767: > > Quoting Felipe Pieretti Umpierre : > >> > Regards, > >> > Everaldo > >> > > >> > On Tue, Feb 7, 2012 at 9:10 PM, Felipe Pieretti Umpierre < > >> > >> I tried, but was the same error. > >> > > > > In the Rails console, pick a model, I use Item here, try this, and show > > us the > > result. > > > >>> i = Item.first > >>> i.title # any string field will do > >>> i.title.encoding > > > > The desired value is: > > > > => # > > > > A couple of other things, I assume you are using Ruby 1.9, correct? And > > did > > you restart your server after changing database.yml? > > > > Jeffrey > > 1.9.3-p0 :003 > group = Group.first > Group Load (0.8ms) SELECT `groups`.* FROM `groups` LIMIT 1 > => # "2012-02-08 22:32:26", updated_at: "2012-02-08 22:32:26"> > 1.9.3-p0 :004 > group.description > => "ahsidaus" > 1.9.3-p0 :005 > group.description.encoding > => # > > My encoding is different... > This is your problem. The ASCII-8BIT string from the database are conflicting with UTF-8 strings in your views. Are you sure you are using mysql2? From the Rails console: >> require 'active_record' >> Group.first >> Mysql2::VERSION => "0.3.11" "0.3.11" is the version of Mysql2 on my system. If it is not defined, try Mysql::VERSION. Presumably that will be defined. You will have to figure out why the wrong gem is used. At the command line "gem list mysql" will tell which are installed. Double check config/database.yml for "adapter: mysql2". HTH, Jeffrey -- 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.
Re: [Rails] Re: Re: Encoding error
Quoting Felipe Pieretti Umpierre : > Everaldo Gomes wrote in post #1044692: > > Hi! > > > > Try to follow Jefrey tip. Because he said that mysql adapter returns > > ASCII-8bit. > > > > You must use > > > > adapter: mysql2 > > > > Regards, > > Everaldo > > > > On Tue, Feb 7, 2012 at 9:10 PM, Felipe Pieretti Umpierre < > > I tried, but was the same error. > In the Rails console, pick a model, I use Item here, try this, and show us the result. >> i = Item.first >> i.title # any string field will do >> i.title.encoding The desired value is: => # A couple of other things, I assume you are using Ruby 1.9, correct? And did you restart your server after changing database.yml? Jeffrey -- 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.
Re: [Rails] Encoding error
Quoting Felipe Pieretti Umpierre : > Hello, I have in my db a register what have special characters, and when > I try to put on my form to edit this values, this happens: > > incompatible character encodings: UTF-8 and ASCII-8BIT > > Extracted source (around line #4): > > 1: <%= form_for :group, :url => { :action => "update" } do |f| %> > 2: <%= utf8_enforcer_tag %> > 3: Nome do grupo <%= f.text_field :name %> > 4: Descrição <%= f.text_area :description, :cols => 60, > :rows => 6 %> > 5: <%= f.submit "Editar grupo" %> > 6: <% end %> > > In my database.yml > > development: > adapter: mysql > enconding: utf8 > database: mailler_development > reconect: false > username: mailler > password: > pool: 5 > timeout: 5000 > > In my list action, I put utf8_encoding( "utf-8" ) to works, but I was > searching and I don't find nothing for form_for. > Try the mysql2 adapter. The mysql adapter always returns ASCII-8BIT strings, even if MySQL is using UTF8 encoding. HTH, Jeffrey -- 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.
Re: [Rails] Application speed up issue
Quoting Srimanta Chakraborty : > Hi, > I have a controller action which is taking 10 seconds to run. Most of > the time is being spent in a view which is a large file.(more than 1500 > lines). How shall I go about debugging the speed issue? > Profile it. See which methods are being called, how often, etc. Google "profile rails request". Jeffrey -- 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.
Re: [Rails] (SOT) Change in em-http-request: 0.3.0 => 1.0.0
Quoting Jeffrey L. Taylor : > I am trying to bring some older code up to date. It works fine with > em-request-http 0.3.0. With 1.0.0 it breaks, revealing my lack of > understanding Ruby, among other things. The following code reveals the > problem: > > require 'rubygems' > require 'eventmachine' > #gem 'em-http-request', '=0.3.0' > require 'em-http-request' > > class PhrcRequest < EM::HttpRequest > def initialize(*args) > puts "HERE" > super(args) > end > end > > r = PhrcRequest.new('http://example.com/') > > puts r.inspect > > > With em-request-http 1.0.0 (the newest version on my system), the output is: > > # @uri="http://example.com/";, @connopts=# @port=80, @tls={}, @proxy=nil, @inactivity_timeout=10, @host="example.com", > @connect_timeout=5>> > > With version 0.3.0 (the gem statement uncommented), the output is: > > HERE > # URI:http://example.com/>> > > Can someone explain to me how calling new() for one class returns an object of > another class? And how I can work around it. And is this a bug in > EM::HttpRequest that I should report? > Use the source! Looking at the 1.0.0 code, it overrides self.new(), doesn't call initialize() and returns an HttpConnection. This strikes me as abuse of the language and certainly violates the principle of least surprise. It also effectively blocks inheritance. Can anyone tell me how this is not a bug? Jeffrey -- 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] (SOT) Change in em-http-request: 0.3.0 => 1.0.0
I am trying to bring some older code up to date. It works fine with em-request-http 0.3.0. With 1.0.0 it breaks, revealing my lack of understanding Ruby, among other things. The following code reveals the problem: require 'rubygems' require 'eventmachine' #gem 'em-http-request', '=0.3.0' require 'em-http-request' class PhrcRequest < EM::HttpRequest def initialize(*args) puts "HERE" super(args) end end r = PhrcRequest.new('http://example.com/') puts r.inspect With em-request-http 1.0.0 (the newest version on my system), the output is: #http://example.com/";, @connopts=#> With version 0.3.0 (the gem statement uncommented), the output is: HERE #http://example.com/>> Can someone explain to me how calling new() for one class returns an object of another class? And how I can work around it. And is this a bug in EM::HttpRequest that I should report? TIA, Jeffrey -- 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.
Re: [Rails] install pauldix-feedzilla
Quoting guru : > urjit@dharin02:~/rails_project/demo1$ sudo gem install pauldix- > feedzirra > [sudo] password for urjit: > ERROR: Could not find a valid gem 'pauldix-feedzirra' (>= 0) in any > repository > ERROR: Possible alternatives: agiley-feedzirra, fblee-feedzirra, > orend-feedzirra, penso-feedzirra, lstoll-feedzirra > gem install feedzirra The rest are presumably forks of Paul Dix. The README.rdoc of the above command results do show "gem install pauldix-feedzirra". Try "gem search feedzirra". HTH, Jeffrey -- 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.
Re: [Rails] Lots of embedded ruby / database queries on a page
Quoting Andrew Brown : > I have a few questions about how well RoR performs under various > 'irregular' circumstances. First, how quickly does rails work when > there are potentially lots of embedded ruby expressions (hundreds) per > page? Also, how well does ruby do when there are perhaps hundreds of > database reads per page? > Use fragment caching so messages are rendered only when they change. See Railscasts #90, http://railscasts.com/episodes/90-fragment-caching HTH, Jeffrey -- 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.
Re: [Rails] apostrophes
Quoting Mlle : > My database is in utf8 but apostrophes are showing up as ’ in my > templates. How can I fix this? > Are your Web pages (probably in layouts) set to UTF-8? For example, it there a line like this in the header? HTH, Jeffrey -- 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.
Re: [Rails] Re: exception handling not working?
Plain "rescue" just catches exceptions derived from the StandardError class. IIRC, "rescue Exception" will catch everything. HTH, Jeffrey Quoting Rajinder Yadav : > OK I figured out this is a bug with webbrick, it errors out and then > crashes! > > I installed passenger + nginx and the code works as expected. > > Rajinder > > On 11-10-25 08:29 AM, Rajinder Yadav wrote: > >I am playing with Rails 3.1.1 and made a simple blog app. > > > >I created a unique index on a field and when I submit a new post, > >it throws an exception if the field is not unique. I've added a > >rescue, but it's not doing anything? What am I doing wrong. -- 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.
Re: [Rails] Delete all cache
Quoting Luk Mus : > Is it possible to delete all rails cache? how? > 'rake tmp:clear' doesn't work. > > config/envinroments/production.rb: > ... > config.cache_store =:file_store, 'tmp/cache/' > ... > Try restarting the Rails server, Webrick, Apache, whatever. HTH, Jeffrey -- 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.
Re: [Rails] Looking for a Rails book for a Ruby programmer
Quoting Mateusz W. : > Hey guys, > > I want to learn Ruby on Rails. I have quite a bit of Ruby experience, > I've been programming in it full time for the past few months. I've been > looking for a book that would give me a good overview of Rails, but that > doesn't go into Ruby specifics. Something short that will get me up to > speed and leaves out everything that I can look up in case I have any > trouble. > > Suggestions? Most of the books that I have looked at so far cover Ruby, > which is not what I want. > Ruby on Rails 3 Tutorial by Michael Hartl and skip Chapter 4 "Rails-Flavored Ruby". This book is a good starting book and may be enough depending on what you want. Also the newest edition of "Agile Web Development with Rails". If you need to get into heavy duty Rails, add "The Rails 3 Way". These last two reccomendations are based on my reading earlier editions. "The Rails Way" had no Ruby sections. AWDR 1st edition had an appendix on Ruby. HTH, Jeffrey -- 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.
Re: [Rails] undefined method `options' for #
Quoting Anait M. : > Hi , I am writing a rake task to consume twitter stream API. The task > contains the following code: > > consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => > 'http://twitter.com') > access_token = > OAuth::AccessToken.new(consumer,ACCESS_TOKEN,ACCESS_TOKEN_SECRET) > oauth_params = {:consumer => consumer, :token => access_token} > EventMachine.run do > # now, let's subscribe to twitter site stream > # check informaiton on twitter site > http = > EventMachine::HttpRequest.new('http://stream.twitter.com/1/statuses/sample.json').get > oauth_helper = OAuth::Client::Helper.new(http, oauth_params) > http.options[:head] = (http.options[:head] || > {}).merge!({"Authorization" => oauth_helper.header}) > http.callback { > p http.response > > EventMachine.stop >} Not sure what you are trying to accomplish here, I'm not familiar with OAuth. A couple of points. The htpp = get statements makes the request, no point in altering the GET request after the fact. Perhaps you want something like: url = ' headers = {'Authorization' => oauth_helper.header} http = EventMachine::HttpRequest.new(url, :head => headers).get http.callback { p http.response EventMachine.stop } HTH, Jeffrey -- 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.
Re: [Rails] Can't upgrade Rails - Failed to build gem native extension.
Quoting jay@oz : > I am new to Rails and attempting to upgrade Rails on my Mac to latest > version so that I can follow the rails tutorial, but I just can't seem > to get anywhere. > > When I attempt to update rails with: $ sudo gem update rails -y, I > receive the following error. > > ERROR: Error installing rails: > ERROR: Failed to build gem native extension. > > > Any ideas what I am doing wrong, or what I can do to upgrade to rails? > > Ruby Version is:1.8.7, patchlevel 174 > Rails current version is: 2.3.5 > > Many thanks in advance.. > > > > Here is the full output when running.. > > iMac:blog jason$ sudo gem update rails -y > > Updating installed gems > Updating rails > Fetching: activesupport-3.1.0.gem (100%) > Fetching: builder-3.0.0.gem (100%) > Fetching: i18n-0.6.0.gem (100%) > Fetching: bcrypt-ruby-3.0.0.gem (100%) > Building native extensions. This could take a while... > ERROR: Error installing rails: > ERROR: Failed to build gem native extension. > > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ > ruby extconf.rb > mkmf.rb can't find header files for ruby at /System/Library/Frameworks/ > Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h > This is the key. Look for ruby.h somewhere else on your system or install a package named ruby-dev or ruby-devel. I don't know Macs, so the exact name may vary. The Ruby package includes just the ruby libraries and executables. Ruby-dev includes header files and other files needed to compile and build Ruby and Ruby native extensions. HTH, Jeffrey -- 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.
Re: [Rails] Re: Weird assignment problem, very confused :(
Quoting sol : > This is really weird, either a bug (it's 3.1 rc5) or I don't know: > > 1) DocType.create(:name => request.remote_ip) > DocType.find_by_name('127.0.0.1') > DocType Load (1.4ms) SELECT "doc_types".* FROM "doc_types" WHERE > "doc_types"."name" = '127.0.0.1' LIMIT 1 > => nil > Dynamic typing is wonderful, until it isn't. My hypothesis is that remote_ip is not a Fixnum or Bignum but a custom class that overrides to_s. To test the hypothesis, I'd run the following in the console of writing to the log. puts request.remote_ip.class puts request.remote_ip puts request.remote_ip.to_s puts "#{request.remote_ip}" puts request.remote_ip.inspect DocType.create(:name => request.remote_ip) DocType.last DocType.create(:name => request.remote_ip.to_s) DocType.last Somewhere in this, I expect the truth will be revealed. A IPv4 address is a 32 bit, unsigned number. It is usually represented/rendered in dotted quad notation, but 0x7F01 or 2130706433 are equally valid representations of the local or loopback interface's IPv4 address. HTH, Jeffrey -- 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.
Re: [Rails] [haml] simple question that would make my life a lot better
Quoting Commander Johnson : > Hello, > > In HAML, is it possible to get this result: > > - link_to "http://www.example.com"; do > - "www" > - "example" > - "com" > What about: - link_to "http://www.example.com"; do - ["www", "example", "com"] Jeffrey -- 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.
Re: [Rails] Use find with a variable
Quoting Leonel *.* : > I got the id of a "part" in variable "the_id". In a partial > "_order_fields.html.erb" > > So I do this... > @a = Part.find(the_id) > > I get this error... > Couldn't find Part without an ID > Uhh, are you sure the_id has a numeric value at that point in the view? You don't say where or how it is set. Local controller variables are not shared with views, though controller instance variables are. And anything can be passed to a partial, though not regular view through the :locals hash. HTH, Jeffrey -- 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.
Re: [Rails] Re: Long polling (comet) on Rails
Quoting Yaroslav Govorunov : > On Aug 14, 1:52 pm, Frederick Cheung > wrote: > > On Aug 11, 12:27 pm, "Yaroslav G." wrote: [snip] > Spreading nodes completely depends on a backend used to store and pass > messages - whether it would be RabbitMQ, database, etc. We only added > non blocking eventmachine support. We have almost all peaces working, > except ability to push data from the script. Our worker uses Rack to > interact with Rails, and Rack does not seem to provide any way to > return partial data to the server. So there is no ability to flush > some part of response to client and send a remaining part later. Still > working on a solution. Possibly the protocol have to be improved. > It is my understanding that flushing partial responses in implemented in Rails 3.1. HTH, Jeffrey -- 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.
Re: [Rails] Javascript/Ajax questions for rails applications
Quoting egervari : > I am loving just about everything in rails right now. I find a lot of > things faster than java and it's a pleasure to work with. > > One area though that I am not sure how to proceed with is ajax/ > javascript. > > For those of you using rails and a lot of ajax, what are your thoughts > on the built-in functionality for javascript? What about jquery-rails? > Do you go with it? Do you fight against it? Do you start from scratch? > Unless you have a lot of existing RJS, don't use jquery-rails. It is not being maintained and is still at jQuery 1.3. IIRC, jQuery 1.6 has been released. jquery-rails was a nice transition point for moving from RJS and Prototype to jQuery. Having done that, I am going to convert all the RJS to straight jQuery and/or move to Coffescript. At this point, unless jQuery-rails is updated from the newer jQuery releases, it is useful only as a transition of existing RJS. Don't write new code for it. HTH, Jeffrey -- 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.
Re: [Rails] Re: each do js problem
Quoting Colin Law : > On 10 May 2011 17:56, Neil Bye wrote: > > Frederick Cheung wrote in post #997768: > > > >> Is this repeated for each comment? have multiple things on the page > >> with the same id is a no-no: ids should be unique > >> > >> Fred > > > > > > This is the full code > > > > <% @user.comments.each do |comment| %> > > <%= comment.body %> > > <%= comment.story_id %> <%= comment.id %> > > > > > > Hide > > > > <% comment.subcomments.each do |subcomment| %> > > > > <%= subcomment.body %> > > > > <%= subcomment.created_at %><%= subcomment.user_id %> > > > > > > <% end %> > > > > <% end %> > > > > Yes it is repeated for all comments. Both comments and subcomments have > > individual id's I don't see you point. > They don't have different ids. Every remark has the ID, 'remark'. Maybe you intended something like: or simply: "> HTH, Jeffrey -- 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] How to handle orphans?
The requirements for my Web app have changed and now instead of destroying an object and all children when it expires, I need to destroy the parent object when the last child is destroyed. Is there a builtin or gem to do this? Is it better to check the cached count in the parent (reference counting) and destroy it when drops to zero when each child is destroyed or periodically scan for parents with no children and destroy them then (garbage collection)? TIA, Jeffrey -- 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.
Re: [Rails] Beginners question | moving a method from controller to model
See inserted comments below. Quoting linda Keating : > I'm learning with the Agile Web Development 4th edition book. I've > built a method in my controller to test that it works, and now I want to > move it to the model. > > *** line_item controller *** > > def create > @cart = current_cart > event = Event.find(params[:event_id]) > @line_item = @cart.add_event(event) > new_capacity = event.capacity > > > respond_to do |format| > if @line_item.save > new_capacity = new_capacity - @line_item.quantity > event.capacity = new_capacity > event.save > > format.html { redirect_to(@line_item.cart, :notice => 'Line item > was successfully created.') } > format.xml { render :xml => @line_item, :status => :created, > :location => @line_item } > else > format.html { render :action => "new" } > format.xml { render :xml => @line_item.errors, :status => > :unprocessable_entity } > end > end > end > > so I started by doing this > > *** > *line_item.rb > > > def decrease_seat_capacity_on_create > > new_capacity = new_capacity - @line_item.quantity > event.capacity = new_capacity > event.save > end > new_capacity and event are local variables in the controller method. They are not accessible in the called model method. @line_item is an instance variable of the controller instance. It is also not accessible in the model method. However it references the same object as self in the model method. Presumably, event is another model. Note: it is possible that a LineItem has an event method because there is an association between Events and LineItems. I don't see any good reason to push this functionality into a model method. The only property of the model that is clearly being used is the quantity attribute/method. Unless the LineItem model includes a reference to an Event (i.e. LineItem belongs to an Event or hasMany Events). It still looks like poor design unless there are several factors not mentioned here. Jeffrey > and made a changed the line_item controller like this > > respond_to do |format| > if @line_item.save > @line_item.decrease_seat_capacity_on_create > > > But I get the error > > undefined method `quantity' for nil:NilClass > Rails.root: c:/webtech/ServerSide/tickets_online > > Application Trace | Framework Trace | Full Trace > app/models/line_item.rb:12:in `decrease_seat_capacity_on_create' > app/controllers/line_items_controller.rb:51:in `block in create' > app/controllers/line_items_controller.rb:49:in `create' > > > So I'm a bit confused about 'quantity'. I've used it in another method > in the line_item.rb and it worked (much to my surprise) but it doesn't > work in this new method I'm writing. > It isn't quantity that isn't working, it is that @line_item is nil (i.e., @line_item of the LineItem instance has not been assigned a value). @line_item is an instance variable in the controller, not in the model. > I really am an absolute beginner so I'm really just guessing most of the > time. Any suggestions or hints would be most appreciated. HTH, Jeffrey -- 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.
Re: [Rails] Re: Out of order Ajax responses
Quoting Ramon Leon : > On 05/05/2011 08:41 AM, Jeffrey L. Taylor wrote: > >function replace_article(id, action) { > > obj = $j('#article_'+id); > > jQuery.ajax({url: '/articles/'+action+'/'+id, type: 'POST', > > data: {_method: 'put'}, > > success: function(data){obj.replaceWith(data);} > > }); > >} > > > > > >Jeffrey > > Look closely at your function, what is the scope of the variable > named obj? Ask yourself what happens when multiple calls to replace > article are sharing a global reference to obj because you forgot to > say var obj. > Duh. Just read about Coffeescript and how it saves you from this mistake. Didn't connect it with my own code. Thank you, Jeffrey -- 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.
Re: [Rails] Re: Out of order Ajax responses
Quoting Frederick Cheung : > > > On May 5, 4:20 pm, "Jeffrey L. Taylor" wrote: > > I have several links on my Website that make Ajax calls and replace an div > > with the response. If I click several of these links quickly, it looks like > > the responses may replace the wrong div. Response times of the server can > > vary wildly, so responses may arrive out of order. Is there a solution > > other > > than always responding with Javascript that replaces the correct div? > > > How are you choosing which div gets replaced at the moment? > A link_to_function calls the jQuery code shown below. 'id' is the primary key of the model for the div surrounding the link. So the div surrounding the link is replaced with the response from the server. function replace_article(id, action) { obj = $j('#article_'+id); jQuery.ajax({url: '/articles/'+action+'/'+id, type: 'POST', data: {_method: 'put'}, success: function(data){obj.replaceWith(data);} }); } Jeffrey -- 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] Out of order Ajax responses
I have several links on my Website that make Ajax calls and replace an div with the response. If I click several of these links quickly, it looks like the responses may replace the wrong div. Response times of the server can vary wildly, so responses may arrive out of order. Is there a solution other than always responding with Javascript that replaces the correct div? TIA, Jeffrey -- 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.
Re: [Rails] Testing download in controller
Quoting David Kahn : > On Sat, Apr 30, 2011 at 8:14 AM, Jeffrey L. Taylor > wrote: > > > How can download of files be tested? The processing of the file is being > > tested okay, but I don't know how to simulate the controller call. > > > > What are you using to test? This is a bit off your topic as it sounds like > you are writing controller specific tests. I used to do that, but in the > last year I have started convering my ui and views heavily with testing and > since doing this I find that I can achieve reasonably also testing the > controller actions. I am sure some will argue against this but in the > interest in time and quality I think I get more bang for my time covering > how the user will use my ui. That said, I use rspec with capybara (steak) > and using capybara, if there is a download link, I just click the link and > then look at the page.body which gives me the content of the downloaded > file. > > I know you should be able to do so in a controller spec/test also, should be > something like calling a get. I am not sure what your method is but if it > has multiple formats then you would have to specify the format in a > parameter I think, or do something like "get '/controller/action/file.pdf" > or something like that. I would google for 'rails test file download', it > looks like you will have some results you can at least piece together. > Oops, I have the directions backwards. I need to simulate/test upload of a file. The user is uploading their RSS feeds in an OPML file (typically exported from Google Reader). I expected this to be an obscure question, so I didn't Google it. It isn't. There are several answers on Stack Overflow and elsewhere. I sucessfully used the answer at the URL below. Note, this has changed in Rails 3. There is a link to the Rails 3 answer in the footnote to the first answer. Jeffrey -- 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] Testing download in controller
How can download of files be tested? The processing of the file is being tested okay, but I don't know how to simulate the controller call. TIA, Jeffrey -- 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.
Re: [Rails] Re: Question about ERB performance
For that level of detail, profiling is probably the way to go. Google "rails profiling" for your options. Jeffrey Quoting egervari : > Oh, I see. Is there any way I can find out how long it's taking to > make the objects? Make an isolated script that does the same thing and > not call into erb at all? Has anyone done these kinds of break downs? > -- 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.
Re: [Rails] How to achieve Google Reader-like layout in Rails?
Quoting Arve Knudsen : > Hi > > I'm trying to create a web application with a UI that is fundamentally > similar to Google Reader, in Rails 3 and probably with some Javascript > toolkit (jQuery?). I'm new to web development (my background is in desktop > application development), however, and after some experimentation with CSS > layout I'm frankly unsure of how to achieve the desired layout. Therefore > I'm hoping someone on this list might provide me with some clues :) > One approach is use Firebug or similar browser debugger to look at the Google Reader page. Of course, you have to know enough HTML/CSS/Javascript to understand what you are looking at. Also, look at the URL below. There are some jQuery fragments thay might be useful. http://coding.pressbin.com/26/Create-a-Google-Reader-knockoff-using-Javascript HTH, Jeffrey -- 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.
Re: [Rails] Can i upgrade a project from rails 1.2.3 to rails 3.0.5 ?
Quoting nishant : > hello, > i have an application which is created in rails 1.2.3 and ruby 1.8.6 > and now i have to upgrade it to rails 3.0.5 and ruby 1.8.7 ? is it > possible? and if yes how ?? can you guys provide me with some kind of > link or reference . > If it were my project, I'd upgrade to the last 1.2 version first. It has deprecation warnings for the upgrade to 2.0. Fix them, then upgrade to 2.0. Check everything into version control. Then try upgrading to 2.3.11. Fix any warnings and run it for a bit to shake the bugs out. Then upgrade to 3.0.6. There is a plugin or gem, rails_upgrade, that checks for deprecated code. Unfortunately, it is not being maintained. From discussions on the rails-core mailing list, is sounds like someone has forked it and is maintaining it. It will help. But the 2.3 => 3.0 upgrade is a many day process. If Ryan Bates has a Railscast on the upgrade, watch it. His screencasts are uniformly excellent. HTH, Jeffrey -- 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.
Re: [Rails] Re: Different GET response w/ wget and w/ em-http-request
Quoting Frederick Cheung : > > > On Apr 3, 5:26 am, "Jeffrey L. Taylor" wrote: > > I am trying to fetchhttp://drdobbs.com/rss/all. With wget or Firefox, works > > fine. With em-request-http, the server redirects to a login page - 302 > > status > > code, HTML response and response LOCATION header set > > tohttps://login.techweb.com:443/cas/login?service=http%3A%2F%2Fdrdob > > +bs.com%2Frss%2Fall&siteId=365&successfulLoginRedirect=http%3A%2F%2Fdrd > > obbs. > > +com%2Frss%2Fall&gateway=true > > > have you tried asking em-request-http to follow redicects? > I have been following redirects manually. I'll try enabling it in the get call. Thanks, Jeffrey -- 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] Different GET response w/ wget and w/ em-http-request
I am trying to fetch http://drdobbs.com/rss/all. With wget or Firefox, works fine. With em-request-http, the server redirects to a login page - 302 status code, HTML response and response LOCATION header set to https://login.techweb.com:443/cas/login?service=http%3A%2F%2Fdrdob +bs.com%2Frss%2Fall&siteId=365&successfulLoginRedirect=http%3A%2F%2Fdrdobbs. +com%2Frss%2Fall&gateway=true Any ideas how to fix this? TIA, Jeffrey -- 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.
Re: [Rails] can i switch to rails 2.3.5 and run a rails 2.3.5 code??
Quoting Rajesh B. : > Hi all, > > i have installed rails 3 using RVM . the prob is now i have two parallel > projects where one is in 2.3.5 and another is in rails3. > [snip] Look in config/environment.rb for a line like this, or add it if necessary: # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION Or as implied by the comment, freeze rails (AKA vendoring Rails). Google 'freeze Rails' for implementation details. HTH, Jeffrey -- 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.
Re: [Rails] Problems with Object#id deprecation
Quoting Rodrigo Alves Vieira : > Hello everyone, in a test helper in my app I call category.id that gets the > id of category in the database. However, when running RSpec I get the > following error: > > As a parla customer > /Users/saulolopes/code/parla/spec/acceptance/support/paths.rb:13: warning: > Object#id will be deprecated; use Object#object_id I use category[:id] instead and it always works as expected. Clumsy, a kludge, but it works. HTH, Jeffrey -- 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.
Re: [Rails] Parslet & Stack size
Quoting PsiPro : > Hello all, > > I am using parslet to do some log-file parsing and have run into the > "stack level too deep" error, and I am only half-way though with > writing the rules for a single line to be parsed. > I don't know the specific technology in Parslet, but if it's a typical recursive descent parser, you have to write your rules for lists a particular way, otherwise they become infinite recursion. The two ways are: list ::= word | word list and list ::= word | list word Which ever one you are using, try the other. And try to reduce your grammar to the smallest piece that breaks, and then work with it until it doesn't. I have been using Ruby and Rails for over 5 years and I have yet to see a stack overflow that wasn't infinite recursion. HTH, Jeffrey -- 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.
Re: [Rails] Problem with render_component and rails 3
Quoting Ricardo Gonçalves Dias : > I have a application that it use view/layout/application.rhtml, in > this file I have: > > <%= render_component :controller => 'car', :action =>'index'%> > > But there is one problem, it display this problem: undefined method > `render_component' for #<#:0xb67e5f34> > > How can I resolve this problem? > IIRC, components have been deprecated since 2.0. There may be a gem or plugin to provide backwards compatibility (that may not have been updated for Rails 3). But, if it were me, I'd update to more modern idioms. Jeffrey -- 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.
Re: [Rails] Re: I am lost .. why this simple code is running well with irb and not in my app... (syntax error)
Quoting Erwin : > I forgot to mention I write in Ruby 1.9.2... but whatever > I should have the same error running irb ... > I replaced this line with a do block and it's running fine ... Did > Einstein said : "Ruby don't play dice" ? > Ah, but God did give electrons a bit of freewill. Ruby interpreters may take similar libertes ;) Jeffrey -- 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] Rails 2.3.11 and I18N question
Due to slightly different Gems on the development and the production machines, I've discovered that Rails 2.3.11 has I18N support in ActiveSupport. Any recommendations on whether to use the i18n gem (currently using 0.5.0) or the I18N support in ActiveSupport (apparently 0.4.1)? TIA, Jeffrey -- 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.
Re: [Rails] caching database result
Quoting Vogon Primo : > Hi guys, > Has ActiveRecord 3 a more complex cache mechanism than version released > with Ruby on Rails 2.0 ? > > And has ActiveRecord the concept of "scope of object identity?" > > obj1 = MyModel.find(1) > obj2 = MyModel.find(1) > > results in two selects and two different object in memory, why? > > Where I could find clear and detailed info about these topics? > The objects are the results of selects. Some other program may have changed the value in between. So the values may be different. Rails does know what other programs are accessing the database. Only the database server knows. And it can cache the result. So two calls to the DB, possibly two different results. Jeffrey -- 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.
Re: [Rails] Re: can you portably store infinity via AR?
Quoting Frederick Cheung : > > On 10 Feb 2011, at 20:20, Robert Walker wrote: > > > Fearless Fool wrote in post #980885: > >> The gist of my question: is there a way to *portably* store and retrieve > >> Infinity in an ActiveRecord float column? > > > > Okay, first some clarifications: > > > > Infinity is not value and cannot be represented by a float (lower case). [snip] > > IEEE floats handle infinity ( > http://www.gnu.org/s/libc/manual/html_node/Infinity-and-NaN.html ). > Definitely not a rubyism > And Not a Number (NaN). IIRC, square root of -1 is NaN. Jeffrey -- 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.
Re: [Rails] RedCloth
Quoting rails.impaired : > RedCloth (4.2.6) was installed via: sudo gem install RedCloth > ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux] > running Ubuntu 10.10 > > No errors during the install > > any ideas?? > > irb(main):001:0> require 'rubygems' > => true > irb(main):002:0> require 'redcloth' > LoadError: no such file to load -- redcloth > from :33:in `require' > from :33:in `rescue in > require' > from :29:in `require' > from (irb):2 > from /usr/local/bin/irb:12:in `' > irb does not has the same loadpath as Rails. Try the Rails console instead. HTH, Jeffrey -- 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.
Re: [Rails] rails hoster recommendation
Quoting frankblizzard : [snip] > i am in germany, so probably a european hoster would be preferred. > thanks for your help > Also worth asking is where are your customers. Near to me, convenient. Near to customers, good service. Jeffrey -- 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.
Re: [Rails] libxml-ruby sax parsing open-uri
Quoting Chris Armstrong : > Hi there, > > I need to connect to an url to download and process an XML document. > Then run through the XML document and save elements in the database. > > There are many howto's on the internet regarding parsing xml files with > SAX opening a file on the filesystem and reading through it. But I could > not find an example of how to read an URL while processing the xml. > The Ruby wrapper around the libxml2 C library (libxml-ruby) supports the DOM (parse whole file into a data structure that can be searched, editted, written back out), SAX, and Reader models. All will handle any IO like class. They don't have to have the whole input in memory, but can repeated call IO#read to parse data as read rather than all at once. Unless you have a hard requirement to use SAX, look at the Reader model. IMHO, it is easier to use. The documentation (http://libxml.rubyforge.org/rdoc/index.html) is very good. Better than libxml2's documentation, IMHO. HTH, Jeffrey -- 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.
Re: [Rails] Re: Scheduled tasks on rails
Quoting Walter Lee Davis : > > On Jan 13, 2011, at 12:36 PM, Donald R. Ziesig wrote: > > >I restrict the ip to 0.0.0.0 (localhost) so no one outside the > >server can use the route. If someone is able to hack into the > >server itself, all bets are off. :-( . So far I haven't had any > >problems, and the site has been up for 3.5 years so far. > > > >local_request? would work too. > > > I need to do something similar -- keep all but cron requests from > the same server from tripping a particular method in my controller. > Can you elaborate on how local_request? could be used for that > purpose? I looked at the documentation, and it appears to be a test > you can run on an exception, but I'm not clear how to employ it -- > what would I use to raise the exception in the first place? > > Is it as simple as this? > > def my_api_method > send_out_a_bunch_of_mail if local_request? > end > > My gut tells me no, there's an object missing here. > The object is an ActiveController instance, i.e. an HTTP request handler. The method checks the IP address of the requester. Jeffrey -- 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.
Re: [Rails] Re: ActiveRecord::StatementInvalid
Quoting Tom Mac : > > but in terms of getting your > > application running can you not just truncate the string to a valid > > length before saving the record? > > Yes that is possible any way not the best. Relating to this two > questions. > 1) Is there any other gem than mysql. I found ruby-mysql but could not > try since it requires ruby >= 1.8.7 . Mine is 1.8.6 > 2) In mysql what is the next option than a text field that handles very > large data > t.text "description", :limit => 16777215 This in MySQL creates a MEDIUMTEXT field with a 24-bit length. There is also a LONGTEXT type with 32-bit lengths. The default is 16-bit lengths. HTH, Jeffrey -- 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.
Re: [Rails] Re: Scheduled tasks on rails
Quoting Owain : > > > > Look at local_request? method in ActionController. > > > > Jeffrey, > > Certainly another option but I would prefer not to have "network > config" logic in my application if I can help it. If you want to > manage all of the housekeeping jobs from a remote curl or put in load > balancers you would need to change code. I prefer to protect > resources like this in my httpd.conf that defines the server and > network environment. > Whatever. Then the question is one for the Apache forums, not Rails. Jeffrey -- 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.
Re: [Rails] Re: Scheduled tasks on rails
Quoting Owain : > > > On Jan 12, 2:54 pm, "Donald R. Ziesig" wrote: > > Douglas, > > > > I have been using cron tasks that invoke curl that invokes the routes > > that perform the periodic tasks for several years. > > Do you wrap some security on those routes at the web-server level or > in the application? If you secure at the webserver, do you do it by ip > address or user/password > Look at local_request? method in ActionController. HTH, Jeffrey -- 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.
Re: [Rails] undefined local variable or method?
Quoting Mauro : > On 26 December 2010 00:35, Jeffrey L. Taylor wrote: > > Quoting Mauro : > >> I have: > >> <%= form_for(@supplier) do |f| %> > >> ... > >> .. > >> <%= render 'sector_categories', :locals => {:f => f} %> > >> > >> in _sector_categories partial I have: > >> > >> > >> > >> <% for category in @categories %> > >> <%= f.check_box :category_ids[], category.id, > >> @supplier.categories.include?(category) %> > >> <%= category.name %> > >> <% end %> > >> > >> > >> > >> Why it says: undefined local variable or method "f"? > >> > > > > As written, you are rendering a template, not a partial. Passing local > > variables to templates is not supported. Do you mean > > > > <%= render :partial => 'sector_categories', :locals => {:f => f} %> > > As you see in http://guides.rubyonrails.org/layouts_and_rendering.html > there is no need to specify :partial. > Look again. Every example on that page with :locals, explicitly specifies :partial. Your way isn't working. How about trying something different. The only way you will find out if the Rails 2 convention, locals only for partials, is or isn't true in Rails 3 is trying it. You have shown that without :partial and possibly some other factor, locals don't work. Change only one thing and run the experiment again. Jeffrey -- 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.
Re: [Rails] undefined local variable or method?
Quoting Mauro : > On 26 December 2010 00:35, Jeffrey L. Taylor wrote: > > Quoting Mauro : > >> I have: > >> <%= form_for(@supplier) do |f| %> > >> ... > >> .. > >> <%= render 'sector_categories', :locals => {:f => f} %> > >> > >> in _sector_categories partial I have: > >> > >> > >> > >> <% for category in @categories %> > >> <%= f.check_box :category_ids[], category.id, > >> @supplier.categories.include?(category) %> > >> <%= category.name %> > >> <% end %> > >> > >> > >> > >> Why it says: undefined local variable or method "f"? > >> > > > > As written, you are rendering a template, not a partial. Passing local > > variables to templates is not supported. Do you mean > > > > <%= render :partial => 'sector_categories', :locals => {:f => f} %> > > But if I create a new application using scaffold I see a code like > this: <%= render 'form' %> and a file _form.html.rb. > So it is a partial but the render command doesn't have :partial. > What's correct? > Rails 2.x or Rails 3? Jeffrey -- 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.
Re: [Rails] undefined local variable or method?
Quoting Mauro : > I have: > <%= form_for(@supplier) do |f| %> > ... > .. > <%= render 'sector_categories', :locals => {:f => f} %> > > in _sector_categories partial I have: > > > > <% for category in @categories %> > <%= f.check_box :category_ids[], category.id, > @supplier.categories.include?(category) %> > <%= category.name %> > <% end %> > > > > Why it says: undefined local variable or method "f"? > As written, you are rendering a template, not a partial. Passing local variables to templates is not supported. Do you mean <%= render :partial => 'sector_categories', :locals => {:f => f} %> HTH, Jeffrey -- 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.
Re: [Rails] Re: `require': no such file to load -- activerecord
Look at the stack dump. One of the Gems or plug-ins is requiring the file. Jeffrey Quoting Mike C : > Thanks for the response! I don't manually include active record > anywhere, so how can I fix this? > > On Dec 11, 10:57 am, "Jeffrey L. Taylor" > wrote: > > Quoting Mike C : > > > > > I'm trying to upgrade my Rails 2.3.5 app to Rails 3, and when I try > > > and start the rails server with 'rails s' I get this: > > > > > /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/ > > > dependencies.rb:239:in `require': no such file to load -- activerecord > > > (LoadError) > > > > The file changed name to active_record, note the underscore. If you upgrade > > from 2.3.5 to 2.3.x latest, it will let you know about such changes via > > deprecation warnings. > > > > HTH, > > Jeffrey > > -- > 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. > -- 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.
Re: [Rails] `require': no such file to load -- activerecord
Quoting Mike C : > I'm trying to upgrade my Rails 2.3.5 app to Rails 3, and when I try > and start the rails server with 'rails s' I get this: > > /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/ > dependencies.rb:239:in `require': no such file to load -- activerecord > (LoadError) > The file changed name to active_record, note the underscore. If you upgrade from 2.3.5 to 2.3.x latest, it will let you know about such changes via deprecation warnings. HTH, Jeffrey -- 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.
Re: [Rails] rails float type number does not work right
Quoting 蕲春人 : > it "should get right settlement percent" do > contract = Contract.new > contract.settlement_percent = 1.1 / 100.0 > contract.settlement_percent.to_f.should == 0.011 > contract.settlement_percent.to_s.should == "0.011" > end > > but test result is : > > Failure/Error: contract.settlement_percent.to_f.should == 0.011 > expected: 0.011, > got: 0.011001 (using ==) > # ./spec/models/contract_spec.rb:16:in `block (3 levels) in (required)>' > Your model of floating point is incorrect. Exact equality with floating point is rarely a good idea. Most modern computers use the IEEE floating point format and arithmetic is done in base 2. There are many base 10 fractions that do not have exact base 2 representations. And once you start doing calculations, they diverge even further. There are several ways around this. The simplest is: contract.settlement_percent.round_with_precision(5).should == 0.011 ('%0.3f' % contract.settlement_percent).should == '0.011' If you have legal requirements (e.g. SEC regulations) on how arithmetic works, you had better write your own class. Depending on floating point on arbitrary architectures to behave in a certain way is inviting trouble. Jeffrey -- 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.
Re: [Rails] will_paginate on enormous tables
Quoting Aldo Italo : > I'm using the plugin will_paginate with a table of more than 100,000 > records, i also do a join with other table. > I'm wondering if will_pagination in my situation is an appropriate > choice, or whether it is better to implement something ad-hoc? > Large joins are generally very slow. If It Were My Code (IIWMC), I'd try it without the join as an experiment, faking or deleting any missing attributes. Another alternative if, the join adds information rather than being part of the order, conditions, etc. is, paginate the main table and do the join in the view on just the page's records. I know: ugly, bad practice, etc. Alternately, do all the database access in your own controller code and pass the the lines/rows to paginate to display pretty w/ page links, etc. IIRC, Ryan Bates has a Railscast on this or I can supply an example from my own code. There are multiple ways to do this. All will be more work than the usual way. But first you need to know where the bottleneck is. Jeffrey -- 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.
Re: [Rails] When was callback registration introduced?
Never mind, bitten by fixtures. They aren't created normally and the callbacks aren't called. Jeffrey Quoting Jeffrey L. Taylor : > I'm using Rails 2.3.5 and finding that for lines like these below in a model, > the block is never executed. Am I doing something wrong or was this > introduced in a later version of Rails? > > before_create :preprocess_score > > def preprocess_score > puts "HERE: #{__LINE__}" > self['score'] = Token.process(token_counts, feed.user_id) > end > -- 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] When was callback registration introduced?
I'm using Rails 2.3.5 and finding that for lines like these below in a model, the block is never executed. Am I doing something wrong or was this introduced in a later version of Rails? before_create :preprocess_score def preprocess_score puts "HERE: #{__LINE__}" self['score'] = Token.process(token_counts, feed.user_id) end OR: before_create do |a| puts "HERE" a.write_attribute('score', Token.process(token_counts, a.feed.user_id)) end TIA, Jeffrey -- 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.
Re: [Rails] Optimization on huge generating xml?
Quoting Samnang : > Hi all, > > Currently, I'm developing a rails app that are heavy generating xml > from restful webservice. My xml representation of web service use > nokogiri gem to generates xml format that match expected format from > client. But the problem is data is quite big around 50, 000 records to > pull out from the table(millions records). I just test in my local > machine, it takes about 20 minutes to get the response from the > request. > > Do you any ideas on how to optimize this problem? I'm not sure if we > don't use ActiveRecord, and we just use pure sql statement to pull out > the data for generating xml, then the performance is huge faster or > not? > Using SQL and libxml2 (libxml-ruby gem) directly instead of ActiveRecord and Nokogiri (which calls libxml-ruby) will cut the run time. I would guess between 2x and 10x, if the code is written with speed in mind. And your code will be bigger and uglier. What's cheaper, computer time or programmer time? How many times will this generation be run? And are there elapsed time constraints (e.g., an excellent 24 hour weather forecast that takes 28 hours to generate isn't useful). Jeffrey -- 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.
Re: [Rails] Re: Re: SOT MySQL index question
Quoting Marnen Laibow-Koser : > Jeffrey L. Taylor wrote in post #959191: > > Quoting Marnen Laibow-Koser : > >> Jeffrey L. Taylor wrote in post #958953: > >> > How should I index the terms table for maximum speed? > >> > >> How can we tell you? You neglected to say how you're using that > >> table...or is the query below the only one you're interested in? > >> > > > > Correct, this is the one I care about. All others are trivial in terms > > of > > resources compared to this one. > > > >> > It doesn't have > >> > to be > >> > Rails migration doable. > >> > >> But it will be, since adding indices generally is. > >> > > > > Composite keys are not supported in stock Rails. > > Composite *primary keys* are not (but there's a plugin). Composite > *indices* are. You can specify multiple columns in add_index. > Sorry I left out a constraint that turned out to be critical. This is the primary and only index on this table. I've tried the plug-in. It was not reliable in my use scenario. > > > And I will not switch > > DB > > servers next week, so having the index creation in portable form is not > > a necessity. > > Never write SQL in Rails unless there's no other way. > If it is feasible in Rails, I do it that way. However, I was explicitly lifting the constraint of doable in Rails for this usecase. If the usecase included dozens of servers and multiple DB server software, then staying in Rails would make sense. I have one production server (with test database) and one or two development setups (with test databases). Setup in the database client program is very doable. Fighting to shoehorn a usecase that Rails does not handle into Rails is not productive. Jeffrey -- 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.
Re: [Rails] Re: SOT MySQL index question
Quoting Marnen Laibow-Koser : > Jeffrey L. Taylor wrote in post #958953: > > How should I index the terms table for maximum speed? > > How can we tell you? You neglected to say how you're using that > table...or is the query below the only one you're interested in? > Correct, this is the one I care about. All others are trivial in terms of resources compared to this one. > > It doesn't have > > to be > > Rails migration doable. > > But it will be, since adding indices generally is. > Composite keys are not supported in stock Rails. And I will not switch DB servers next week, so having the index creation in portable form is not a necessity. > > E.g. a primary key of (user_id, article_id, > > fnv) is > > okay. fnv is a 63 bit Fowler-Noll-Vo hash. > > > > > > def self.neighbors(user_id, article_id) > > sql = "SELECT t1.article_id, SUM(t1.freq * t2.freq) AS cosim FROM " > > \ > > "tokens AS t1 JOIN tokens AS t2 " \ > > "ON t1.fnv = t2.fnv WHERE t1.user_id = #{user_id} AND t2.user_id = > > #{user_id} AND " \ > > "t1.scoring = 1 AND t2.scoring = 0 AND t2.article_id = #{article_id} > > GROUP BY t1.article_id " \ > > "ORDER BY cosim DESC LIMIT 3" > > connection.select_rows(sql) > > end > > Run EXPLAIN SELECT on this query (or whatever your DB's equivalent is). > See where it's doing full table scans and add indices as appropriate. > > mysql> explain extended SELECT t1.article_id, SUM(t1.freq * t2.freq) FROM tokens AS t1 JOIN tokens AS t2 ON t1.token = t2.token AND t1.user_id = 1 AND t2.user_id = 1 AND t1.scoring = 1 AND t2.scoring = 0 GROUP BY article_id; ++-+---+--+---+--+-+--+---+--+--+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra| ++-+---+--+---+--+-+--+---+--+--+ | 1 | SIMPLE | t1| ALL | user_id | NULL | NULL| NULL | 34773 | 100.00 | Using where; Using temporary; Using filesort | | 1 | SIMPLE | t2| ALL | user_id | NULL | NULL| NULL | 34773 | 100.00 | Using where; Using join buffer | ++-+---+--+---+--+-+--+---+--+--+ 2 rows in set, 1 warning (0.07 sec) mysql> show warnings; | Level | Code | Message | Note | 1003 | select `tv2sql_development`.`t1`.`article_id` AS `article_id`,sum((`tv2sql_development`.`t1`.`freq` * `tv2sql_development`.`t2`.`freq`)) AS `SUM(t1.freq * t2.freq)` from `tv2sql_development`.`tokens` `t1` join `tv2sql_development`.`tokens` `t2` where ((`tv2sql_development`.`t2`.`scoring` = 0) and (`tv2sql_development`.`t1`.`scoring` = 1) and (`tv2sql_development`.`t2`.`user_id` = 1) and (`tv2sql_development`.`t1`.`user_id` = 1) and (`tv2sql_development`.`t2`.`token` = `tv2sql_development`.`t1`.`token`)) group by `tv2sql_development`.`t1`.`article_id` | TIA, Jeffrey -- 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.
Re: [Rails] How do I make an email system that works for my site?
Quoting Mr Mody : > I want to build an app where users can send emails within the site, as > well to a client like gmail. Sort of how myspace.com sends emails > within its self, As well as gmail. Is there a book that explains how to > do both? > The answer depends enormously on what the operating system is. Jeffrey -- 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] SOT MySQL index question
How should I index the terms table for maximum speed? It doesn't have to be Rails migration doable. E.g. a primary key of (user_id, article_id, fnv) is okay. fnv is a 63 bit Fowler-Noll-Vo hash. def self.neighbors(user_id, article_id) sql = "SELECT t1.article_id, SUM(t1.freq * t2.freq) AS cosim FROM " \ "tokens AS t1 JOIN tokens AS t2 " \ "ON t1.fnv = t2.fnv WHERE t1.user_id = #{user_id} AND t2.user_id = #{user_id} AND " \ "t1.scoring = 1 AND t2.scoring = 0 AND t2.article_id = #{article_id} GROUP BY t1.article_id " \ "ORDER BY cosim DESC LIMIT 3" connection.select_rows(sql) end TIA, Jeffrey -- 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.
Re: [Rails] Start mongrel in ssh session and then exit in Ubuntu 10.04
Quoting Duy Lam : > Hi all, > > I'm deploying a Rails application in a Ubuntu 10.04 server with > mongrel web server. I connect to server and do stuffs in a ssh client > (PuTTY). And I'm getting stuck with a strange issue: > 1. After I connected to server, I start mongrel with : $ start-stop- > daemon -S -d . -x script/server -b -- -p 8080 > 2. I left the ssh console and launch firefox from my Win7 box and open > the website, it runs well. I can see the homepage > 3. I go back to the ssh console. Close the terminal (and window too) > it by : $ exit > 4. Then in firefox, I press F5 to refresh and nothing shows up. It's > just an empty space in whole webpage. I tried to use addon to capture > the HTTP data and see that the server returns nothing , even HTTP > headers > > I thought that using start-stop-daemon command could help me run > mongrel as daemon and then I can exit my session just as apache does. > But it doesn't work. > Possible workaround, ssh into server, at shell type "screen", hit space bar, start server, type control-A control-D to detach from screen, logout of SSH session. Later you can log in and type "screen -r" to resume the screen session. I also find this very useful for long operations on remote systems that might lose the connection (e.g. dialup and wifi). HTH, Jeffrey -- 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.
Re: [Rails] rake and stderr
Quoting Jonathan Rochkind : > Why can't I get a rake task to write to stderr? > > warn "something" > $stderr.puts "something" > What about: STDERR.puts "something" HTH, Jeffrey -- 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.
Re: [Rails] Re: http caching a dynamic page
As you noted, etags et al doesn't work for dynamic pages. You can use memcache for rendered fragments of a page as well as objects. Jeffrey Quoting badnaam : > Yes, it seems the whole notion of etags, last_modified is pretty > useless for even remotely dynamic pages. For example, let's say If am > shows a list of posts on a Post Index action. I can may be generate > etags based on the Post count and send a 304 back, but if that page > has a navbar that shows the current logged in users, even that > information is not updated, it essentially it seems is telling the > browser load the entire page for that action from cache. > > Don't most apps similar structure (a username at the top, may be a > badge or something that is specific to a logged in user), how would > you etag these kind of pages? > > > > On Oct 4, 5:05 pm, "Jeffrey L. Taylor" wrote: > > Quoting badnaam :> Is it possible to take advantage > > of http caching/proxy caching with > > > dynamic pages? i.e. pages with section/part that can change over time > > > but certain part of the page remain the same. I would rather not keep > > > re-rendering the static part but insure the dynamic part are rendered > > > with fresh data. > > > > > I am using memcached mostly as an object store that I can minimize db > > > hits but I still am rendering a bunch of views over and over again. > > > > > What's the general best practice to deal with something like this.. > > > > [snip] > > > > If favorite_count is rendered at one end or the other, you can use fragment > > caching and memcache for the unchanging part. Or two fragments if > > favorite_count is in the middle. > > > > HTH, > > Jeffrey > > -- > 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. > -- 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.
Re: [Rails] http caching a dynamic page
Quoting badnaam : > Is it possible to take advantage of http caching/proxy caching with > dynamic pages? i.e. pages with section/part that can change over time > but certain part of the page remain the same. I would rather not keep > re-rendering the static part but insure the dynamic part are rendered > with fresh data. > > I am using memcached mostly as an object store that I can minimize db > hits but I still am rendering a bunch of views over and over again. > > What's the general best practice to deal with something like this.. > [snip] If favorite_count is rendered at one end or the other, you can use fragment caching and memcache for the unchanging part. Or two fragments if favorite_count is in the middle. HTH, Jeffrey -- 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.
Re: [Rails] Re: Re: Re: Re: Authlogic Rails 3
Quoting Paul Mr : > Paul Mr wrote: > > Rick R wrote: > >> On Sun, Sep 12, 2010 at 10:14 PM, Paul Mr wrote: > > > > thats what Im betting on. > > Pretty much.. that one creates all the models/scaffolds/controllers the > usual way...not even caring about Authlogic::Session::Base > > though I assume possibly, manually editing the one item to reflect that > instead of activerecord (or whatever it was). > -- IIRC, AuthLogic works w/ Rails 3, but doesn't have the new generator structure. Generate it in Rail 2.x and copy the files over. Jeffrey -- 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.
Re: [Rails] schedule to run a method?
Quoting Ichiro Saga : > Hi, everyone. I wrote a ror app. One of the methods in controller > extracts data from files and saves it to database. Because there are > many new files every night, is it possible to run this method only every > night or every other night? Thanks in advance. > Simplest way in Linux/Unix/MacOSX is with cron and 'script/runner Class.class_method' or something similar. Probably best to run it as same user as the Rails server to avoid permission problems. There are other ways that may be more appropriate in some cases. If you care to share more details I could recommend an ever better method. Jeffrey -- 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.
Re: [Rails] Will a Quad-core i5 processor significantly speed up development on Linux or Mac?
Quoting BlueHandTalking : > I am looking at getting a new Thinkpad with an i5 processor. > > I was curious to what extent this would speed up developing a Ruby on > Rails > app. I am guessing that this depends to what extent multi-threading is > utilized, > but I am not sure---hence the question :^) > Ruby (at least for 1.8) does not use multiple cores. However, the database server may. And test suites usually hit both. A talk was given at Lone Star Ruby on how the speaker reduced the run time for the test suite from 13 minutes to 18 seconds. Part of the changes involved running pieces of the test suite in parallel on multiple CPUs. I am pretty sure the talk is on the Web somewhere. Google for "Grease your Suite: Tips and Tricks for Faster Testing". HTH, Jeffrey -- 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.
Re: [Rails] Re: Freeze an attribute?
Quoting Frederick Cheung : > > > On Sep 9, 2:11 am, "Jeffrey L. Taylor" wrote: > > Is it possible to to freeze a single attribute of an ActiveRecord (Rails > > 2.3.5). Hopefully in a way that isn't deprecated in 2.3.8 or 3.0. > > > attr_readonly ? > Not quite what I wanted, but interesting none the less. I wanted an attribute that could not be modified in memory. From the documentation, this allows it to be modified, but won't write the modified value to the DB. I think a way to do this is create the value on object instantiation, freeze it, and then assign it to the attribute. It's a calculated value in an ActiveRecord that has associated objects. I want to make sure, one of the associated objects doesn't modify the value. No write accessor just prevents changing the attribute to refer to a different object. It does not prevent modifying the assigned object. Thanks, Jeffrey -- 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] Freeze an attribute?
Is it possible to to freeze a single attribute of an ActiveRecord (Rails 2.3.5). Hopefully in a way that isn't deprecated in 2.3.8 or 3.0. TIA, Jeffrey -- 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.
Re: [Rails] Re: unable to upload larger files
Quoting Amit Tomar : > Jeffrey L. Taylor wrote: > > Quoting Amit Tomar : > >> hii, > >> i am trying to upload some files to filesystem using rails application > >> when i use small size file everything is perfect but i when goes for > >> larger files i got error > >> this is my code > >> > > > > Check the Webserver's (e.g. Apache) file size limit. It may be set to > > some > > small value. > > > > HTH, > > Jeffrey > > Thanks for responding Jeffrey > > but i am new to rails ,so where do i find Webserver file size limit ,am > running > mongrel as server and one more thing i would like to mention is when am > trying to upload large file (320 mb),file is being uploaded to phyical > location but i am getting error like > > Invalid argument - > //192.168.147.27/Smruti/streams/predator_720x480_5mbps_30fps_17minclip.264.filepart > > When i looked into the streams folder file is there... > I don't know Mongrel, but I'd look in the Mongrel configuration file. I expect Mongrel is cutting off or aborting the file transfer and then throwing the InvalidArgument exception. In Nginx, the setting is: client_max_body_size 0; # don't limit the upload file size In Apache, the setting is: LimitRequestBody 50 Look for something similar. HTH, Jeffrey -- 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.
Re: [Rails] unable to upload larger files
Quoting Amit Tomar : > hii, > i am trying to upload some files to filesystem using rails application > when i use small size file everything is perfect but i when goes for > larger files i got error > this is my code > Check the Webserver's (e.g. Apache) file size limit. It may be set to some small value. HTH, Jeffrey -- 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.
Re: [Rails] invalid byte sequence in UTF-8 , need to re-encode ?
Quoting Erwin : > > > I have a string coming from an email body : > (rdb:1) body > "\r\nLe 3 sept. 2010 \340 19:06, Event Seve Test a \351crit :\r\n\r\n> > Please answer the question by writing an X at the chosen places :\r\n> > \r\n> are you coming : \r\n> \r\n> YES: X\r\n> \r\n> NO:_\r\n> \r > \n> thanks for you answer\r\n> \r\n> the Seve Ballesteros" > > when I want to resent this boy in another email, I get an error , > stating invalid byte sequence .. sure the \r\n are causing the error > > (rdb:1) sending_confirmation_email(@origin, @destination, @subject, > @message) > ArgumentError Exception: invalid byte sequence in UTF-8 > > should I strip them ? or is there any way to re-encode the string in > UTF-8 ??? ( Ruby 1.8.3 and Ruby 1.9.2 ) > What is the original encoding? It doesn't look like UTF-8. \r and \n are ASCII and so okay in UTF-8. It is the \340 and \351 that look suspicious. Jeffrey -- 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.
Re: [Rails] Re: Rails 3 install on Ruby Enterprise
Quoting Charlie B99 : > Veera Sundaravel wrote: > > May be this link will help you. > > http://veerasundaravel.wordpress.com/2010/02/15/rails3-beta-installation/ > > > > > Still receive error installing rails: active model requires i18n > When I try to sudo gem install i18n, it errors out because it requires > RubyGems 1.3.6 or higher. I have RubyGems 1.3.7 installed. WTF? > I received this error too after installing Ruby Enterprise Edition (REE). RubyGems apparently knows which version or at least path of Ruby it was installed with and complains in the very unhelpful way you noted about the conflict. Try changing your PATH shell variable so MRI Ruby is before REE Ruby. HTH, Jeffrey -- 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.
Re: [Rails] Re: Removing just leading and trailing newline characters
Quoting Marnen Laibow-Koser : > Priya Saini wrote: > > Hi: > > > > I am using FCKeditor in one of my form, when i copy and paste something > > into it using WordPaste, it appends few newlines at the beginning and at > > the end. > > How can i strip just those \n without effecting the inbetween newlines > > and the formatting. > > > > This is probably best done with a regular expression. > Isn't this just what String#strip does? Jeffrey -- 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.
Re: [Rails] Re: Ruby question, max length of strings
Quoting Paul Harrington : > Paul Harrington wrote: > > Jeffrey L. Taylor wrote: > >> Am I correct in assuming that the max length of a string is 65,535 on a > >> 32 bit > >> platform? Anyway around this, other classes, 64 bit platform? > >> > >> TIA, > >> Jeffrey > > > > What would make you assume this? Simplest demonstration: > > > > irb(main):004:0> s = "a"*7;nil > > => nil > > irb(main):005:0> s.size > > => 7 > > irb(main):006:0> > > > > Also, keep in mind Ruby has no separate representation for raw 8bit > > data. Only Strings. How would it be able to store a 65KB+ file in > > memory? > > > > The only limit to Ruby string is is available memory. > > btw that irb session was > irb(main):001:0> RUBY_VERSION > => "1.9.1" > irb(main):002:0> RUBY_PLATFORM > => "i386-mingw32" I find the same results. Checking further, I find that it's MySQL TEXT column that is limited to 65,535 bytes. Thank you, Jeffrey irb(main):001:0> s = "a"*7;nil => nil irb(main):002:0> s.size => 7 irb(main):003:0> RUBY_VERSION => "1.8.7" irb(main):004:0> RUBY_PLATFORM => "i586-linux" irb(main):005:0> -- 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] Ruby question, max length of strings
Am I correct in assuming that the max length of a string is 65,535 on a 32 bit platform? Anyway around this, other classes, 64 bit platform? TIA, Jeffrey -- 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.
Re: [Rails] save! neither saves nor raises error
Quoting Fearless Fool : > I don't like this. This makes me grumpy, and I've even already had my > morning coffee. > > obs[0] is a PremiseObservation, save! completed without error, yet > nothing was written to the db. This is a serious ass-biter: > > irb(main):057:0> PremiseObservation.count > => 0 > irb(main):058:0> obs = > PremiseObservation.get_premise_observations(premise) ; obs.size > => 320 > irb(main):059:0> obs[0].is_a?(PremiseObservation) > => true > irb(main):060:0> obs[0].save! > => true > irb(main):061:0> PremiseObservation.count > => 0 > Try 'obs[0].touch'. Quoting the documentation at http://rails.rubyonrails.org/: touch(attribute = nil) Saves the record with the updated_at/on attributes set to the current time. If the save fails because of validation errors, an ActiveRecord::RecordInvalid exception is raised. If an attribute name is passed, that attribute is used for the touch instead of the updated_at/on attributes. Examples: product.touch # updates updated_at product.touch(:designed_at) # updates the designed_at attribute HTH, Jeffrey -- 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.
Re: [Rails] Search large XML file -- REXML slower than a slug, regex instantaneous
Quoting David Kahn : > Got a question hopefully someone can answer - > > I am working on functionality to match on certain nodes of a largish (65mb) > xml file. I implemented this with REXML and was 2 minutes and counting > before I killed the process. After this, I just opened the console and > loaded the file into a string and did a regex search for my data -- the > result was almost instantaneous. > > The question is, if I can get away with it, am I better off just going the > regex route, or is it really worth my while to investigate a faster XML > parser (I know REXML is notorious for being slow, but given how fast it was > to call a regex on the file, I am thinking that this will still be faster > than all parsers). > Look at using LibXML::XML::Reader http://libxml.rubyforge.org/rdoc/index.html What most XML parsing libraries are doing is reading the entire XML file into memory, probably storing the raw text, parsing it, and creating an even bigger data structure for the whole file, then searching over it. Nokogiri at least does some of the searching in C, instead of Ruby (it uses libxml2). With LibXML::XML::Reader is possible (with some not very pretty code) to make one pass thru the XML file, parsing as you go, and create data structures for just the information of interest. Enormously faster. HTH, Jeffrey -- 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.