[Rails] Re: Hook into Exception Chain

2013-11-12 Thread Jeff Lewis
re-raising > exceptions is considered to be bad :) > > Thanks a lot, > Christoph > > On Tuesday, 12 November 2013 19:07:00 UTC+1, Jeff Lewis wrote: >> >> Hi Christoph, >> >> All you need to do is re-raise the exception after you're done using it >> in

[Rails] Re: Hook into Exception Chain

2013-11-12 Thread Jeff Lewis
Hi Christoph, All you need to do is re-raise the exception after you're done using it in your rescue_from, so something along the lines of: $ cat ./app/controllers/foo_controller.rb ... rescue_from Exception do |e| # do something with e before re-raising it ... Rails.logger.debug("TEST

[Rails] Re: LDAP gems: paged search with net-ldap

2012-10-01 Thread Jeff Lewis
Hi Adam, I haven't used net-ldap gem (I've always just used ruby-net-ldap gem for past several yrs for various projects), but ... Here's a link to the specific note in the current src regarding that setting: https://github.com/RoryO/ruby-net-ldap/blob/master/lib/net/ldap.rb#L1337 Jeff On Frid

[Rails] Re: error ncompatible character encodings: UTF-8 and ASCII-8BIT

2012-01-01 Thread Jeff Lewis
The problem you're running into has to do with encoding mismatch (under ruby 1.9) in some data you're munging/rendering in that view. First thing you should do is check your config/setup regarding encoding: $ ./script/rails console...> __ENCODING__ => # > Encoding.default_internal => # > Encoding.d

[Rails] Re: How can I get RVM/Passenger/Apache2 to play nicely together

2011-12-14 Thread Jeff Lewis
Hi Vell, Once you figure out that apache vhost path / read issue on your new setup, If you're using passenger and you're running rvm, then you're likely using (or will use) different rubies and/or gemsets for projects on a given machine. If so, then you might want to consider using passenge

[Rails] Re: Error for uuid

2011-12-08 Thread Jeff Lewis
If you don't really need a real uuid, you could just gen something similar yourself using ActiveSupport::SecureRandom.hex: ... def gen_uuid_ish s = ActiveSupport::SecureRandom.hex(16) [ s[0..7], s[8..11], s[12..15], s[16..19], s[20..-1] ].join('-') end ... which will produce strin

[Rails] Re: additional model attributes

2011-10-25 Thread Jeff Lewis
One alternative in terms of dynamically adding an attribute to a model instance (without having to have pre-defined any attr_... in the class): ... place = Place.new place.name = place.name place.id = place.id place['address'] = external_api_place_data.address ... >From then on, for t

[Rails] Re: Character encoding problems.

2011-09-06 Thread Jeff Lewis
Hi Perry, I've run into such encoding issues under ruby 1.9.x and rails 3.x when dealing with unknown/untrusted/bad non-utf8 data params that need to be handled by the rails app as utf-8. The fix I found (that works for the needs of my apps) was by following a strategy outlined by Paul Battley (h

[Rails] Re: background task

2011-07-25 Thread Jeff Lewis
Hi John, What I usually do in cases like yours is that I'll create a runnable script that is run using rails runner (like $ ./script/rails runner -e production ./script/fetch_save_foo.runnable), and then use cron to run that script on some ongoing basis (where I typically have a crontab per projec

[Rails] Re: looping through results of complex query

2011-07-09 Thread Jeff Lewis
For anyone that's interested You can inspect the model's current attributes to see that additional data that was added in your custom query: ... puts("herd_ration: #{herd_ration.attributes.inspect}") ... Jeff On Jul 9, 10:11 am, clem_c_rock wrote: > appreciate your reply Fred  

[Rails] Re: Encoding

2011-06-21 Thread Jeff Lewis
t; the error and it didn't work.  The problem is with microsoft word > special characters.  I can't find a way to replace these characters. > Here is one website I found that describes the special > characters:http://www.toao.net/48-replacing-smart-quotes-and-em-dashes-in

[Rails] Re: Encoding

2011-06-17 Thread Jeff Lewis
Hi Erica, I ran into similar situation a while ago for a webservice app I was working on where I had to handle a lot of bad / untrusted non-utf8 data, and found a fix that met the needs of the app using Iconv (http://www.ruby-doc.org/stdlib/libdoc/iconv/rdoc/index.html) following a strategy outlin

[Rails] Re: implementation feedback appreciated

2011-03-08 Thread Jeff Lewis
Hi Erwin, What you're wanting to do really should be done using asynchronous processing. Progress monitoring has two simultaneous things going on: the potentially long-running work being performed; and the monitoring of that work's progress. Synchronous processing implies that only one thing can

[Rails] Re: Help hacking AR timestamps

2011-03-04 Thread Jeff Lewis
Hi Kendall, Note that on the rails side of things, both rails db schema definitions datatypes :datetime and :timestamp will result in values returned as class Time for use in your rails app: $ cat /active_record/connection_adapters/abstract/ schema_definitions.rb ... # Returns the Ruby

[Rails] Re: how to solve this problems gracefully

2011-01-28 Thread Jeff Lewis
Hi dan, You could do something like: ... posts = [] if not name.blank? or not title.blank? sql_buf = [] vals_buf = [] if not name.blank? sql_buf << "name=?" vals_buf << name end if not title.blank? sql_buf << "title=?" vals_buf << title end

[Rails] Re: rvm and phusion passenger

2011-01-05 Thread Jeff Lewis
Hi Tom, If you are or can run passenger 3.x, then you can use passenger- standalone proxy'd via apache to handle multiple / different ruby/ rails combinations. Check out http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/ "One of the questions we’ve been getting

[Rails] Re: Customize validation output

2010-12-31 Thread Jeff Lewis
Hi djangst, When model validation rules result in errors, those errors are basically made available to you as an ordered hash where the keys are symbols of the attribute names and the values are strings/arrays of the error(s) for the attribute. So if you had some model foo.rb: class Foo < Active

[Rails] Re: activeldap anyone using?

2010-12-29 Thread Jeff Lewis
Hi Mauro, Whenever I've needed to work with ldap in ruby or rails, I've always just used ruby-net-ldap: https://github.com/roryo/ruby-net-ldap/ "... Net::LDAP is a pure Ruby library. It does not require any external libraries. You can install the RubyGems version of Net::LDAP available from the

[Rails] Re: Weird issue with converting floats to integer

2010-12-23 Thread Jeff Lewis
Or just change the way you calculate to get at the level of accuracy that you want/need: irb> ("291.15".to_f * 1000.0).to_i/10 => 29115 Jeff On Dec 22, 7:41 pm, Marnen Laibow-Koser wrote: > TomRossi7 wrote in post #970207: > > > Any idea why this calculates the integer the way it does? > > > ir

[Rails] Re: Design Question - re: Polymorphic association

2010-12-07 Thread Jeff Lewis
Hi Randy, Hard to say for sure without knowing the specific needs/requirements/ demands of your app, but... if your app is a typical biz or ecomm app backed by an rdbms where most of the usage (for end users and for analysis) of the app is spent doing reads vs writes, when it comes to the

[Rails] Re: Overriding or aliasing name of column in legacy database using Rails/ActiveRecord

2010-12-04 Thread Jeff Lewis
Hi Mike, Having a db table column named object_id is going to be a problem for any ruby-based app, given object_id's significance as an object attribute in ruby (http://www.ruby-doc.org/core/classes/ Object.html#M000339). If your rails app only needs to read from (and not write to) that legacy ta

[Rails] Re: Better approach to set global values?

2010-11-24 Thread Jeff Lewis
Another alternative is to just use the existing rails environment config or initializers file(s) to store such info in memory, something like: $ cat ./config/environment.rb ... APP_VALS = { :default_company_name = 'My Company', } ... $ ./script/console ... >> APP_VALS[:default_company_name] =>

[Rails] Re: Rails & ImageMagick CLI Backticks

2010-06-14 Thread Jeff Lewis
On your server, try capturing stderr to see if that gives you any info that might help (maybe PATH issue?): $ ./script/console production >> puts `convert --version 2>&1` ... Jeff On Jun 14, 1:13 am, Greg Willits wrote: > Rails 2.3.2, OSX 10.5.8, Ruby 1.8.6 (p369), IM 6.5.0 > > I have my own c

[Rails] Re: Accessing session data from a background worker

2010-05-27 Thread Jeff Lewis
Not sure what you are attempting to accomplish in those background threads/processes, or what the reasoning is behind even using multiple background threads/processes in the first place in light of what you seem to be trying to do, but the basic strategy you're attempting to pursue where you have m

[Rails] Re: Accessing session data from a background worker

2010-05-25 Thread Jeff Lewis
A couple of problems that jump out regarding accessing/using session data in that strategy you outlined: - the background threads/processes might end up using invalid session data if the session data changes during the time from when you pass in that session_id and when some background thread/pro

[Rails] Re: Accessing session data from a background worker

2010-05-24 Thread Jeff Lewis
How about just passing in the session data hash when you call the particular workling ob method, something like: ### in ./app/workers/foo_worker.rb class FooWorker < Workling::Base def bar(options) session_data = options[:session_data]) # do something with session.data hash ...

[Rails] Re: Newbie Q - JSON

2010-05-24 Thread Jeff Lewis
Hi Henry, Doesn't include any err testing/checking, but ... you could do something like: ### in some rails project root: $ cat ./tmp/t.runnable def parse_lat_lng(json_str) lat, lng = [0.0, 0.0] location = JSON.parse(json_str)['results'][0]['geometry'] ['location'] lat, lng = location['lat']

[Rails] Re: Controller/Action Problem

2010-05-18 Thread Jeff Lewis
Hi Tobias, Another alternative to Rob's suggestion, ... if you can, I'd recommend bailing on mongrel altogether, and just switch to running your rails apps under passenger (ie mod_rails / mod_rack) via apache or ngnix. Passenger can handle more than one request to your rails app at a time, thus no

[Rails] Re: Combining multiple finds into one result

2010-05-14 Thread Jeff Lewis
>From the rails api docs examples (http://api.rubyonrails.org/classes/ ActiveRecord/Base.html#M002263): ... # find all Person.find(:all) # returns an array of objects for all the rows fetched by SELECT * FROM people Person.find(:all, :conditions => [ "category IN (?)", categories], :limit =>

[Rails] Re: Combining multiple finds into one result

2010-05-14 Thread Jeff Lewis
The .find_by_(...) meth returns the first model object found (or nil if none found), whereas .find(:all, ...) meth returns an array: $ ./script/console >> puts Foo.find_by_id(1).class Foo >> puts Foo.find_by_id(0).class NilClass >> puts Foo.find(:all).class Array Jeff On May 14, 12:09 pm,

[Rails] Re: HTML and CSS to PDF

2010-05-13 Thread Jeff Lewis
Not really a valid test of prince then is it? Kind of like testing a toaster that wasn't plugged in: "hey, this toaster is junk, ... it didn't even heat up the bread". --Jeff On May 13, 9:48 am, Jonathan Steel wrote: > Colin Law wrote: > > On 13 May 2010 17:40, Jonathan Steel wrote: > >> mism

[Rails] Re: HTML and CSS to PDF

2010-05-13 Thread Jeff Lewis
Sounds like the underlying html/css in your "complicated" test might not be valid, such that prince is saying that it isn't able to generate the pdf because it can't parse/process that html/css? You might want to run that html/css thru a validator first, like http://validator.w3.org/ , to first fi

[Rails] Re: HTML and CSS to PDF

2010-05-13 Thread Jeff Lewis
Hi Jonathan, I've used prince on a few projects running in production in the past couple of years and have nothing but good things to say about it. Not sure what problems you experienced when you tried prince out, but I have yet to see any problems with it. If you can't afford the license for pr

[Rails] Re: Disable Logging on a Controller/Action

2010-04-27 Thread Jeff Lewis
Hi Tom, Not sure if it applies to your specific case, but whenever I come across the need to quiet the logging activity for some particular verbose-under-normal-logging activity process that I'm really only concerned about logging-wise only if it fails, ... I usually just temporarily up the log-le

[Rails] Re: puzzled by Mutex lock call ..

2010-04-22 Thread Jeff Lewis
Not sure what the purpose of your use of such a mutex lock is in your app, but if it's something other than restricting access to some resource amongst some threads handled within a given instance of your rails app running in some process, but in terms of rails, I don't think a mutex lock will

[Rails] Re: Allow '.' to be a part of identifier, not a separator of format

2010-04-17 Thread Jeff Lewis
In your ./config/routes.rb, you could do something like: ... map.connect '/movies/:title', :controller=>'movies', :action=>'by_title', :requirements=>{:title=>/[-_+.a-z0-9]+/i} ... See Regular Expressions and Parameters on http://api.rubyonrails.org/classes/ActionController/Rou

[Rails] Re: confirm b4 submit?

2010-04-15 Thread Jeff Lewis
(removed and re-posted) An alternative strategy, assuming your app can use javascript on the client, would be to confirm the user's action first via javascript on the client-side before allowing the user to submit the form back to the server. There are many ways to do this, but the one I use most

[Rails] Re: confirm b4 submit?

2010-04-15 Thread Jeff Lewis
An alternative strategy, assuming your app can use javascript on the client, would be to confirm the user's action first via javascript on the client-side before allowing the user to submit the form back to the server. There are many ways to do this, but the one I use most these days is to have a

[Rails] Re: Friendly way to deal with invalid authenticity_tokens?

2010-04-15 Thread Jeff Lewis
re: reachability of referer req: Yes, if the screen that they had just submitted the post req from that resulted in the failure had previously been reached via a post req, then they wouldn't be sent back to that particular page. But, even if this were the case, wouldn't (shouldn't?) the routing/r

[Rails] Re: Friendly way to deal with invalid authenticity_tokens?

2010-04-14 Thread Jeff Lewis
Hi Max, The strategy I usually follow is catch the error, log it (and check logs periodically to make sure it's not really an xss attack), set a msg for the user about the problem, and then redirect the user back to where they came from, something along the lines of (in app/controllers/ applicatio

[Rails] Re: SystemTimer failing

2010-04-05 Thread Jeff Lewis
Hi Marcelo, Not to avoid your specific SystemTimer and ldap timeout issue, but Have you thought about trying the pure-ruby ldap lib Net::LDAP (http://net-ldap.rubyforge.org/) instead of the c-based Ruby/ LDAP lib you're currently using (http://sourceforge.net/projects/ruby- ldap/)? I've alw

[Rails] Re: Ruby-ldap timeout

2010-04-01 Thread Jeff Lewis
Hi Marcelo, If that ldap lib doesn't include any timeout settings/params for timing out long-running ldap calls (which if you're talking about ruby- net-ldap, it doesn't at this time), then one way would be to wrap those potentially-long-running calls in ruby's timeout (http://ruby- doc.org/core/c

[Rails] Re: POST-only logic in protect_from_forgery considered harmful?

2010-04-01 Thread Jeff Lewis
This seems like a non-issue to me that can and should be handled by the developer of the app, regardless of what lang/framework you're using, by following basic best-practices for securing your app against csrf or sql-injection or ... attack. So in your post example, if you didn't want to restrict

[Rails] Re: Add all metods in ssl_required

2010-03-27 Thread Jeff Lewis
Ryan, If you are using or can use passenger to serve your production env, then an alternative that would make this a non-issue would be to use passenger to serve your development env as well. That way you'd be able to use ssl in dev env just as you would in prod env. Another benefit would be tha

[Rails] Re: need to parse a User uploaded file, but don't care if it's saved

2010-03-24 Thread Jeff Lewis
t storing the file, then > deleting it later? > > I'm just asking, I honestly don't know.  Also, while the file uploads, > a Rails process is not tied up, correct?  It's actually being buffered > by the server? > > A big thank you Jeff, and to anyone else that wants to

[Rails] Re: need to parse a User uploaded file, but don't care if it's saved

2010-03-23 Thread Jeff Lewis
One way would be to just process the uploaded-file data from the request as needed and not worry about saving or doing anything else with the tmp-saved uploaded-file itself, something like: ### in ./app/models/uploadable_file.rb class UploadableFile ### for use in testing: def initialize(fna

[Rails] Re: selective migrations possible?

2010-03-19 Thread Jeff Lewis
It's the same basic strategy I've been using successfully for the past 15+yrs dev'ing and maintaining web apps, using various mvc frameworks, langs, etc. Don't follow it if you don't want, but it's one that's worked well for me, based on real-world experience, and saved me a lot of time/headaches.

[Rails] Re: How to save rails generated pages to a file on the server

2010-03-19 Thread Jeff Lewis
Since I started using tools (like prince/wkhtmltopdf) to generate pdfs from html/css for web app projects that need to gen pdfs, I've never gone back to using low-level pdf-gen'ing libs/tools (like prawn). Just requires so much less work. By the way, you may also want to look into using http://www

[Rails] Re: How to save rails generated pages to a file on the server

2010-03-19 Thread Jeff Lewis
You might want to check out: http://code.google.com/p/wkhtmltopdf/ http://www.princexml.com/ wkhtmltopdf is free. prince will cost you. prince has better css print-related implementation coverage at this time, but wkhtmltopdf can be a very good alternative depending on the needs of your project

[Rails] Re: selective migrations possible?

2010-03-19 Thread Jeff Lewis
Hi Grar, If you really want to call a single migration, you could do something like: $ ./script/console ... >> require "#{RAILS_ROOT}/db/migrate/100_create_foos.rb" => ["CreateFoos"] >> CreateFoos.down == CreateFoos: reverting = -- drop_table(:foos) ... >> ActiveRec

[Rails] Re: How to use ruby script/console to debug methods in appl

2010-02-09 Thread Jeff Lewis
Hi Lukas, You definitely can, by adding some temporary debug puts calls interspersed in your method, and then calling your method either using ./script/runner or from within a ./script/console session. To make that method easier to test, I'd relocate that method outside of ./app/controllers/appli

[Rails] Re: Administrative task in Rails

2010-02-04 Thread Jeff Lewis
Hi Vincent, To answer your initial idea, Yes, you can create a script, using the same calls you would make in console, and run them using ./script/ runner. I do this all the time for various scripting tasks for projects. One of the great features of rails. You could do something like:

[Rails] Re: Generating a PDF using popen and wkhtmltopdf

2010-02-02 Thread Jeff Lewis
(reposted due to typo... ) Hi Nicolas, Whenever I generate pdfs from a rails app using wkhtmltopdf (or princexml), I usually call wkhtmltopdf using an app_url (ie wkhtmltopdf hits the web app to get the html/css/imgs/... to be used to gen the pdf), something like the following: # in some contr

[Rails] Re: Generating a PDF using popen and wkhtmltopdf

2010-02-02 Thread Jeff Lewis
Hi Nicolas, Whenever I generate pdfs from a rails app using wkhtmltopdf (or princexml), I usually call wkhtmltopdf using an app_url (ie wkhtmltopdf hits the web app to get the html/css/imgs/... to be used to gen the pdf), something like the following: # in some controller require 'timeou

[Rails] Re: Best Practices; Deploying Updates

2010-01-28 Thread Jeff Lewis
Hi Dan, Depends on the needs/functionality of your app, but the two things I usually incorporate in my web apps to address production environment upgrades/maintenance are: 1) the ability to render a real-time system-wide message to all current users of the app; and 2) the ability to toggle on/of

[Rails] Re: Accessing Raw Post Data

2010-01-17 Thread Jeff Lewis
$ irb irb(main):001:0> "foo".to_sym.class => Symbol irb(main):002:0> :foo.to_s.class => String Jeff On Jan 17, 4:19 pm, doug wrote: > > I'd avoid using Net::HTTP to do anything > > Thanks for the input.  Your point is well taken. > > None-the-less, I'd still like to be able to do this.  The pr

[Rails] Re: Accessing Raw Post Data

2010-01-17 Thread Jeff Lewis
I'd avoid using Net::HTTP to do anything but the most simple of httpclient work. You'll save a ton of time/effort by using a more full featured httpclient to perform your POST. There are a lot of ruby httpclient options out there. Which one to use kind of depends on which one you like using that

[Rails] Re: Accessing Raw Post Data

2010-01-15 Thread Jeff Lewis
To get an array of ordered keys for the POSTed keys/vals, you could do something like: ... if request.post? ordered_keys = request.raw_post.split('&').collect {|k_v| CGI::unescape(k_v.split('=').first.to_s) } ... and then use those ordered_keys in to access the params vals to accomplish

[Rails] Re: Generating views in pdf, rtf, or doc format

2010-01-15 Thread Jeff Lewis
Hi Brian, I'd definitely recommend going with pdf, and use either princexml (http://www.princexml.com/features/) or wkhtmltopdf (http:// code.google.com/p/wkhtmltopdf/) to generate pdfs from your app's html/ css. You'll save a ton of time and effort using one of these two tools, since you'd be wo

[Rails] Re: Mongrel to Apache

2010-01-11 Thread Jeff Lewis
For mongrel deployment behind apache, you might want to check out: http://mongrel.rubyforge.org/wiki/Apache Instead of mongrel, you may want to look at deploying via passenger: http://www.modrails.com/install.html Jeff On Jan 9, 12:05 pm, Derek Smith wrote: > Hi All, > > We have a RoR app, SQLi

[Rails] Re: tinyint(1) and boolean

2010-01-11 Thread Jeff Lewis
I second Matt's point about potential for confusion. A boolean val implies one of two values: true or false. What you're asking for -- 1 of 3 potential vals -- seems to rule out the use of a boolean to represent that val. So, I'd recommend using some other data type. Jeff On Jan 10, 11:57 am,

[Rails] Re: how to time out a query

2009-10-13 Thread Jeff Lewis
Another alternative would be to just wrap your long-running query in a timeout, something like: require 'timeout' ... begin status = Timeout::timeout(60) do # some long-running action end rescue Timeout::Error => te # end Jeff On Oct 13, 1:07 pm, JohnB wrote: > You've proba

[Rails] Re: Calling partials from onother controller/view

2009-10-08 Thread Jeff Lewis
To render the partial, try: ... <%= render :partial=>'shared/albums' %> ... Jeff On Oct 8, 2:09 am, Nuno Neves wrote: > Hi, > > I'm learning rails and my first application is a simple gallery that > pulls photos from flickr using flickraw. > > The site has 3 main zones: > > Left: where all

[Rails] Re: How disable log for entire action?

2009-09-28 Thread Jeff Lewis
How about up'ing the logger level temporarily, like ... bak_log_level = logger.level begin logger.level = Logger::ERROR # do some stuff ... ... ensure logger.level = bak_log_level end ... Jeff On Sep 28, 5:38 pm, Greg Willits wrote: > Philip Hallstrom wrote: > > On

[Rails] Re: Encode and Encrypt Email Addresses

2009-09-28 Thread Jeff Lewis
Hey Tom, Instead of encrypting/decrypting some data, one typical approach to do this type of thing is to employ (cryptographic) hashing to verify that some requested action is valid, as well as to try and discourage malicious request attempts. You could try something like: ### in routes: ... ma

[Rails] Re: boolean model.column? == true even if value is 0

2009-07-27 Thread Jeff Lewis
For those that are interested, ... the discussion in the AWDR book that preceded that particular quote and the suggested action for dealing with differences in underlying db storage of boolean vals: ... # DON'T DO THIS ... if user.supervisor ... # INSTEAD, DO THIS ... if user.supervisor? ... Je

[Rails] Re: .html/.html.erb/.rhtml to PDF

2009-07-14 Thread Jeff Lewis
I've always just used the statically compiled version of wkhtmltopdf (for testing). If you can't use the static version, might want to search/work-with-maintainers to resolve build-from-src problems. Best of luck, Jeff On Jul 14, 1:03 am, Sandip Ransing wrote: > Hi Jeff > > svn checkouthttp:/

[Rails] Re: .html/.html.erb/.rhtml to PDF

2009-07-13 Thread Jeff Lewis
I'd also recommend princexml if you can afford it. And I'm a big f/ oss proponent. Been using it on a couple of apps for clients in the past couple of years and have been very happy with results. The coverage of (standard) print-related css is very good. I can't tell you how much time has been

[Rails] Re: accessing model attribute name dynamically

2009-07-13 Thread Jeff Lewis
Maybe I'm not understanding what you're sending as a val for @field, because if it's a string of the model attribute name, it should work: $ script/console >> klass = Klass.find(:first) => # >> klass.foo => "bar" >> klass["foo"] => "bar" >> klass["foo"] = "biz" => "biz" >> klass["foo"] => "b

[Rails] Re: accessing model attribute name dynamically

2009-07-13 Thread Jeff Lewis
Another alternative: ... @meta[field] = content ... Jeff On Jul 13, 9:32 am, Dan Berger wrote: > Jamey Cribbs wrote: > > How about: > > > @meta.send("#{field}=", content) > > > Jamey > > > On Fri, Jul 10, 2009 at 4:31 PM, Dan > > That's it. Thanks! > -- > Posted viahttp://www.ruby-forum.

[Rails] Re: rails environment in scripts dir

2009-06-19 Thread Jeff Lewis
Or another alternative is to create some runnable script and run it against the environment you want: $ cat ./script/do_some_foo.runnable puts " fetching all foo in #{RAILS_ENV} env:" Foo.find(:all).each do |foo| // do something with foo ... end ... $ ./script/runner ./script/do_some_foo.run

[Rails] Re: Sessions in Rails 2.3?

2009-06-12 Thread Jeff Lewis
Hi Alex, If you're using rails 2.3.2, take a look at ./config/initializers/ session_store.rb. There you'll see what you're looking for: ... #ActionController::Base.session_store = :active_record_store ... Jeff On Jun 11, 8:10 am, Alex Barlow wrote: > Hi guys, new here so bonjour.. > > Sorry

[Rails] Re: Calculating the Date of the Start of Week

2009-05-20 Thread Jeff Lewis
Not sure if this is what you're looking for, but if you wanted to find the prev Mon and next Sun for some given date/time for use in querying/ comparing, you could do something like: $ irb > t_now = Time.now => Wed May 20 17:50:56 -0700 2009 > t_prev_mon_begin = t_now - (t_now.wday-1)*24*60*60 -

[Rails] Re: problem with nil.user

2009-04-29 Thread Jeff Lewis
Just to followup if you're interested, the error msg from the op was due to the fact that the call to session[:user_id] returned nil, and thus calling find(nil) resulted in that error being raised. If you wanted to avoid such an error and just have the find call return nil if not found, one

[Rails] Re: Rails, multiple connections and threads

2009-04-29 Thread Jeff Lewis
Might want to try: ... fork { `ruby #{RAILS_ROOT}/script/some_script.rb` } ... Jeff On Apr 29, 7:57 am, Sudhi Kulkarni wrote: > Hi, > > I have a rails app which currently does the following > > "After the launch of the page, there is a button click which starts > another ruby script on

[Rails] Re: background process fork - generating zip files

2009-04-24 Thread Jeff Lewis
>From that first link I provided: "... dizave: Are you guys seeing performance problems with the fact that rails controllers are essentially forced to single-threaded under mongrels? ... Zed A. Shaw: dizave, just wanted to clarify that Rails is always single threaded, even under FastCGI, SCGI, a

[Rails] Re: background process fork - generating zip files

2009-04-24 Thread Jeff Lewis
If you have a single instance of mongrel running your rails app, then it is essentially "single threaded" when it comes to handling requests (see comments in http://weblog.rubyonrails.org/2006/5/18/interview-with-mongrel-developer-zed-shaw or http://mongrel.rubyforge.org/wiki/FAQ or ). Like

[Rails] Re: Getting list of drives using ruby on rails

2009-04-24 Thread Jeff Lewis
Might want to try: ... mapped_drives = `net use`.chomp.split ... or whatever the ms-windows shell command is that displays what drives have been mapped on the machine (note that I haven't used ms-windows in over a decade or so, nor have access to test, ...). Jeff On Apr 23, 12:08 am, Mur

[Rails] Re: Changing Passwords in Active Directory with ruby-net-ldap

2009-04-22 Thread Jeff Lewis
Try replace_attribute: http://net-ldap.rubyforge.org/rdoc/classes/Net/LDAP.html#M30 from rdoc example for updating mail attribute: dn = "cn=modifyme,dc=example,dc=com" ldap.replace_attribute dn, :mail, "newmailaddr...@example.com" I haven't worked with Active Directory specifically, so

[Rails] Re: background process fork - generating zip files

2009-04-21 Thread Jeff Lewis
Are you seeing this behavior while running your rails app under a typical development environment setup, ie a single mongrel instance of the dev env running? If so, then the blocking/hanging is due to the fact that your archiving meth is trying to make an httpclient call (using wget) back into yo

[Rails] Re: keep 404's out of my logs

2009-04-16 Thread Jeff Lewis
Or you could just define a catch-all route as your last defined route, and do something like the following: # last route defined in routes.rb: ... map.connect '*path_leftovers', :controller=>'testapp', :action=>'pre_404' ... # in testapp_controller.rb or application(_controller).rb:

[Rails] Re: Silence logging altogether for certain actions?

2009-04-16 Thread Jeff Lewis
(re-posted) One way that might meet your needs is to just up the log level temporarily: ... bak_log_level = logger.level begin logger.level = Logger::ERROR # or some other uppper log level ... # stuff you want to perform but restrict logging ... ... rescue ... ensure

[Rails] Re: Silence logging altogether for certain actions?

2009-04-16 Thread Jeff Lewis
One way that might meet your needs is to just up the log level temporarily: ... bak_log_level = logger.level begin logger.level = :fatal # or some other uppper log level ... # stuff you want to perform but restrict logging ... ... rescue ... ensure logger.level = b

[Rails] Re: background process fork - generating zip files

2009-04-14 Thread Jeff Lewis
One way you could do it: # in your model meth: def generate_archive was_success = false ... fname = "#{dir}/#{title}.zip" ... prev_fsize = 0 10.times do # or some reasonable(?) max num times. sleep 0.5 begin fsize = File.size(fname); rescue; fsize = 0;

[Rails] Re: LDAP Authentication Failed

2009-03-20 Thread Jeff Lewis
Hi Palani, If you're trying to auth against ldap using Net::LDAP, might want to try: ... require 'net/ldap' LDAP_HOST = '127.0.0.1' # or match your setup. LDAP_PORT = 389 # or ... LDAP_DN = 'cn=shalini,ou=people,dc=mips,dc=com' # or ... ... def ldap_auth(uid, pss) return fa

[Rails] Re: crypto in Rails 2.x?

2009-03-10 Thread Jeff Lewis
I'm not a cryptographer, but One way you could do this, depending on your app requirements, is to follow an asymmetric encryption strategy using pub/priv keys, something like: ### gen pub/priv keys to use: $ cd ./private $ openssl genrsa -out asym_priv.key 2048 ... $ openssl rsa -in asym_

[Rails] Re: Executing a ruby file

2009-03-02 Thread Jeff Lewis
Hi Sudhindra, Depending on the needs/requirements of what you're trying to do, you could probably get away with exec'ing your ruby file in a subshell and direct output as needed. Take a look at Kernel module backtics (http://www.ruby-doc.org/core/ classes/Kernel.html#M006001) and read up on vari

[Rails] Re: Using variable class names, how?

2009-03-01 Thread Jeff Lewis
My example used clss not class, ... but sure klass if you prefer. Jeff On Mar 1, 11:32 am, Phlip wrote: > Jeff Lewis wrote: > >   def first_last_count(clss) > > Note the tradition there is klass: > >    http://google.com/codesearch?q=lang%3Aruby+klass > >

[Rails] Re: Using variable class names, how?

2009-03-01 Thread Jeff Lewis
Instead of passing class names as strings, why not ref the classes themselves? Lame example, but ... something like: ... def first_last_count(clss) return [clss.find(:first), clss.find(:last), clss.count] end ... first_car,last_car,count_cars = first_last_count(Car) ... first_

[Rails] Re: warning users that the site is coming down for maintenance

2009-02-28 Thread Jeff Lewis
Hi Yoram, There are lots of different approaches, especially depending on what your app does and how it is implemented, but I usually do something like the following, which works for both development env (setup to re- reload all code/templates/etc on each request) and production env (setup to re-

[Rails] Re: Rails on Apache

2009-02-24 Thread Jeff Lewis
Instead of fastcgi, you might want to look into using mongrel (http:// mongrel.rubyforge.org) instead: http://mongrel.rubyforge.org/wiki/Apache Jeff On Feb 24, 4:27 am, Angappan Ayyavoo wrote: > http://firstruby.wordpress.com/2007/03/21/deploying-rails-with-apache... > -- > Posted viahttp://ww

[Rails] Re: Updating database via cron?

2009-02-23 Thread Jeff Lewis
(removed/reposted) One of the things I've loved about rails is the ease with which you can leverage your existing app code for shell/cli/scripting purposes using ./script/console and ./script/runner. As such, I highly recommend implementing your parsing/processing code from within your rails app

[Rails] Re: Updating database via cron?

2009-02-23 Thread Jeff Lewis
One of the things I've loved about rails is the ease with which you can leverage your existing app code for shell/cli/scripting purposes using ./script/console and ./script/runner. As such, I highly recommend implementing your parsing/processing code from within your rails app, versus having some

[Rails] Re: How do I access a variable defined in application.rb from within application.rhtml?

2009-02-22 Thread Jeff Lewis
To initialize some db-read var (tidbit in your example) that would survive and be callable for each subsequent app request, you'll want to do so via lazy-initialization using a before_filter (mentioned by bill) in application.rb. How you store such lazy-init vars between requests depends on the s

[Rails] Re: PDF Generation with password

2009-02-20 Thread Jeff Lewis
I agree with Bill. pdftk has been an invaluable tool for me when working with pdfs, and can easily be wrapped for use in ruby. Altho you'll want to add checks to ensure safety of params your passing to pdftk, and check for errors returned, ..., you could do something like: ... def add_use

[Rails] Re: test db missing constraints

2009-02-18 Thread Jeff Lewis
ll having problems, maybe post your specific config/setup and code? Jeff On Feb 18, 1:23 pm, Greg Donald wrote: > On Wed, Feb 18, 2009 at 2:03 PM, Jeff Lewis wrote: > > Then, after migrating, that constraint should show up in db/ > > development_structure.sql, which your

[Rails] Re: Switching to ActiveRecord Session Store

2009-02-18 Thread Jeff Lewis
Hi John, Hard to tell, but I'm wondering if you forgot to run rake:db:migrate after running rake db:sessions:create? The latter creates the migration file in db/migration/, and the former actually creates the table in the db. Check your db to make sure the sessions table does exist. If you di

[Rails] Re: How to convert xls to csv?

2009-02-18 Thread Jeff Lewis
Hi Salil, To convert xls to csv and then parse for use in ruby, you could try wrapping xls2csv (http://www.wagner.pp.ru/~vitus/software/catdoc/) and parsing via CSV (http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/ index.html), something like: $ irb irb(main):001:0> require 'csv' => true irb(mai

[Rails] Re: test db missing constraints

2009-02-18 Thread Jeff Lewis
Hi Greg, Here's a simple mysql-specific example for adding cascade delete constraint, for authors0..*books, that should give you an idea of what to do in your oracle proj (using oracle-specific constraints): # in config/environment.rb: ... config.active_record.schema_format = :sql ...

[Rails] Re: post to external form

2009-02-18 Thread Jeff Lewis
Hi Frank, What you need to do is a bit of http client programming. There are lots of options, including: http://dev.ctor.org/http-access2 http://rfuzz.rubyforge.org http://curb.rubyforge.org ... Whatever you use depends on your needs/tastes. A simplified (non-error-checked) example of retriev

  1   2   >