[Rails] Re: ActiveSupport Dependencies load eats MultiJson.load?
Nevermind! Indeed, nobody else reported the problem because there is no problem. Due to weirdnesses of my Gemfile.lock, I was using a really old version of multi_json without realizing it, one that lacked the #lock method. (Had an old version of Capybara in my gemfile.lock, which locked multi_json dependency to an old version of multi_json, which kept multi_json from ever updating, bah). On Wednesday, December 5, 2012 3:47:19 PM UTC-5, Jonathan Rochkind wrote: > > I can't quite figure out what's going on here, it seems like if this were > actually a problem someone else would have run into it and I'd have better > luck googling for it, since MultiJson is so popular but > > Rails 3.2.9. Is ActiveSupport::Dependencies doing something weird with a > #load method defined on all objects, such that it conflicts with other > objects #load method? > > MultiJson wants you to use MultiJson.load to parse JSON. > > But when I try somehow some activesupport load is eating it instead. I > get an error "Could not load file [big json string]", and this odd > stacktrace: > > activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load' > activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `block in > load'", > active_support/dependencies.rb:236:in `load_dependency'", > activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'", > > line to my app code that's actually calling MultiJson.load, but then the > next line up is an active_support load instead, what now? > > Anyone have any idea how I would debug this further, or what might be > going on? Any known problems with ActiveSupport adding a 'load' which > kills other gems loads? > -- 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. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/SXvDyL73BW4J. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] ActiveSupport Dependencies load eats MultiJson.load?
I can't quite figure out what's going on here, it seems like if this were actually a problem someone else would have run into it and I'd have better luck googling for it, since MultiJson is so popular but Rails 3.2.9. Is ActiveSupport::Dependencies doing something weird with a #load method defined on all objects, such that it conflicts with other objects #load method? MultiJson wants you to use MultiJson.load to parse JSON. But when I try somehow some activesupport load is eating it instead. I get an error "Could not load file [big json string]", and this odd stacktrace: activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load' activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `block in load'", active_support/dependencies.rb:236:in `load_dependency'", activesupport-3.2.9/lib/active_support/dependencies.rb:245:in `load'", line to my app code that's actually calling MultiJson.load, but then the next line up is an active_support load instead, what now? Anyone have any idea how I would debug this further, or what might be going on? Any known problems with ActiveSupport adding a 'load' which kills other gems loads? -- 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. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/l1vTMPFtOB4J. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] isolated engine, routing helpers, testing?
I believe this is a missing feature/bug, but when I tried to file an issue (https://github.com/rails/rails/issues/6573) I was told to post it here instead. So, okay, doing my duty! I suspect that nobody will pay any attention to this, and a year from now when someone google's for this issue this post is going to be all they find, but I'd love to be proven wrong! I believe there is no way using the standard supported Rails testing framework to test routes from an `isolated` engine. Or to test helpers that use these routes. I believe there is no way to test isolated engine helpers or use isolated engine helpers in tests. But I'd be pleased if I'm wrong and I'm just missing something. If you create an isolated engine, then the dummy app has a config/ routes that has for instance mount Widget::Engine => "/widget" If the Widget engines has it's own config/routes, then ordinarily an app with that line in it would be able to access the engine's route path helpers as widget.some_path. That works in the app. But it does not work in the test environment. No such method widget, the widget. method isn't installed in the test environment. The main engine root widget_path => /widget is installed in the testing environment, you can use it in tests and test routing involving that named helper and path. But not any of the specific widget routes that would ordinarily, in an actual app, be available at widget.some_path. Phew, this is confusing to talk about, hope this is understandable. I guess I'll keep hacking away at it and looking at Rails source, maybe file a pull request if I can figure out what's going on, but this is very convoluted code, even before you pull the testing environment into it. -- 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] xhr and format.js
I am getting confused about the relationship between respond_to/format.js and an xhr request. Would appreciate any advice, tips on how this has changed in different Rails versions if it has, etc. In particular, I am confused as to why an xhr request sometimes will trigger format.js, even though it's not actually a request to format=>js, but other times won't. And if I want to take some special action in response to xhr requests, is it best practice to check request.xhr?, or to use format.js? I am adding some unobtrusive JQuery JS of my own (not using the Rails helpers), which submit to the same controller actions as the ordinary HTML actions. But when a request is received from an xhr, the controller should do something different -- for instance, not do a redirect, or return just a partial instead of the full HTML (the JQuery will grab the partial and insert it into the page itself). What is the best practice for having a controller action recognize an xhr request, and respond differently? In some sample code on the net, I see "format.js". Which confuses me a bit, because the JS code isn't actually making a .js request, it's still requesting .html -- but sometimes format.js seems to match it _anyway_, and I don't know why. Other times it does not. I can not predict it. Or, I can actually manually test for "if request.xhr" and just "render" what I want manually if so, if not do the whole respond_to thing. But that gets a bit odd too. Are there best practices for this stuff? For having a controller action that responds differently to an xhr request from JS than to an ordinary browser HTML request? When I google around, people seem all over the place on this, it seems to have changed a lot in different rails versions, etc. Any advice appreciated. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: distance_of_time_in_words shows {{count}} days instead of showing actual days
Colin Law wrote in post #968871: > On 15 December 2010 19:07, Amit Ambardekar wrote: >> Time to show next topic {{count}} days > Are you using internationalisation? If so then it could be an issue > there. > > Google for > time to show in words rails count > produced some possibilities including > http://stackoverflow.com/questions/4330403/time-ago-in-words-in-count-days > > Colin >From way back, I'm still having this problem. With rails 2.3.5 and ruby 1.8.7. The problem does NOT appear in ruby 1.8.6, only 1.8.7. It may be fixed in future versions of Rails, but future 2.3.x have OTHER bugs I don't want, and I don't have time to do the complete upgrade to 3.x yet. Very annoying! If anyone sees this and has any more info on it, please do let me know. Otherwise maybe I'll just have to downgrade to 1.8.6 again. I upped to 1.8.7 because I had been reading people berating those who had stuck at 1.8.6 instead of at least staying current in 1.8.x -- but this is not the only bug or weird thing I've run into with Rails 2.x and 1.8.7 so far. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Rails2 routing guide?
Anyone know if the old Rails2 version of the Routing Guide at http://guides.rubyonrails.org/routing.html is still available anywhere? I still have some Rails2 apps to support, and that guide was very useful, I'm missing the Rails2 version. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] rake and stderr
Why can't I get a rake task to write to stderr? warn "something" $stderr.puts "something" Both result in no output in my console. Anyone know what's up? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] streaming response body to client?
So I'd like to stream my response body to the client. At least under Rails2, it looks like you can pass a Proc to render :text, to do that. I am in a Rails2 app right now, but will upgrade to Rails3 sometime in the next couple months, so don't want to set myself up for failure. Anyone know the status of streaming responses in Rails3? Is it possible? Is there a different API to do so? (Seems like using Rack api, it definitely must be possible, since Rails3 is all rack, and rack is fine with iteratively-delivered responses, but it's not entirely clear to me how to do it). On top of that, even in Rails2, I'm having an awful lot of trouble setting custom headers in the response using the render :text => proc pattern. The proc, according to what limited docs I've found, takes two args, the first one is a 'response', which I should be able to set headers on, but I can't seem to make them stick. Can anyone give me the lowdown on streaming responses in Rails? Maybe a good example, even one that sets headers too? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Browser caching of Rails assets -- for real
While Rails adds a ?timestamp query string to the end of asset URLs, under passenger+apache deployment (and I suspect most other deployment), these actually have no effect whatsoever on browser caching. In some cases this might not matter to you much — if you are able to use the Rails helper :cache=>’filename’ argument, or if you don’t have very many asset files, or if you aren’t trying to wring every last bit of performance out of your app. But sometimes you really do want your Rails assets to be cached for real by the browser, without even an if-modified check. Below is a way to kind of hackily set up your apache conf to do so. [btw, wouldn't it be nice if Passenger would do this automatically for Rails, avoiding the need for a hack?] http://bibwild.wordpress.com/2010/09/22/browser-caching-of-rails-assets-for-real/ -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: add a member to a pre-existing resource-route?
Marnen Laibow-Koser wrote: > Jonathan Rochkind wrote: >> Rails2. If a route has already been established with "map.resources", >> is there any way I can add an additional member to it, without >> over-writing what's already there? > > Just define the route as you normally would (with map.connect ). > map.resources is not magical; it's just shorthand for a bunch of > map.connect statements. Ah, i was worried that my second map.resources would 'over-ride' certain things from the first one. But it looks like it doesn't. If you call map.resources once with certain :members, and then call it again with another :member... it LOOKS like indeed all the aggregated members are now there. Cool. Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] add a member to a pre-existing resource-route?
Rails2. If a route has already been established with "map.resources", is there any way I can add an additional member to it, without over-writing what's already there? This comes up in two engines-style plugins interacting with each other and with the app itself. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-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] url_for escape=>false, builder xml template?
The Rails documentation says "When called from a view, url_for returns an HTML escaped url. If you need an unescaped url, pass :escape => false in the options. " But I can't seem to get this to work, :escape => true has no effect at all. Is this because I'm in an .atom.builder view, not an .html.erb view, is it somehow different? Taking the example from the docs itself: <%= url_for(:action => 'checkout', :anchor => 'tax&ship', :escape => false) %> # => /testing/jump/#tax&ship Not for me. For me, with that exact call with :escape => true, I still get: => ...checkout#tax%26ship (tested with ruby-debug itself, in a view. So I know it's not some later layer escaping it before it gets to the browser or something). Is this a bug? Is it a bug only in atom.builder or something, or something else i have yet to isolate? Or am I doing something wrong? Any advice? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: Multiple Databases using an abstract class - help
Jonathan Rochkind wrote: > An AR model for a particular table, as you can see you can even use AR > associations (to other tables within the same db! Trying to make > associations cross-db tends not to work): > http://umlaut.rubyforge.org/svn/trunk/app/models/sfx_db/object.rb Heh, I also see reviewing old code I haven't looked at for a while, that naming one of my own classes "Object" probably wasn't a great idea, even if it is in a module namespace. Don't copy that part. :) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: Multiple Databases using an abstract class - help
Kim wrote: > To clarify: > Some of the data for my rails app is stored in a non-rails DB table. I > need to query this other database and then show the data in the rails > app. I can only tell you what I did when I needed to do this. I did NOT use find_by _sql, I actually set up ActiveRecord classes for each table in the 'non rails DB'. You can actually specify everything you need in ActiveRecord to over-ride rails conventions. I did have several of these tables in the same 'non-rails' DB, so they DID have a common abstract superclass with a connection. Here's the code, actually why copy and paste when I can link you to svn. An AR model for a particular table, as you can see you can even use AR associations (to other tables within the same db! Trying to make associations cross-db tends not to work): http://umlaut.rubyforge.org/svn/trunk/app/models/sfx_db/object.rb And the superclass that pretty much just establishes the connection (also note it uses an AR feature to make everything read-only, cause that's what I wanted in this case): http://umlaut.rubyforge.org/svn/trunk/app/models/sfx_db/sfx_db_base.rb Once I set that up, I can and do use ordinary AR stuff with those models, no need for find_by_sql and such. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] render html partial from atom builder
So I have an action that results in atom: def index ... respond_to do |format| ... format.atom { render :layout => false} end end Then I have a builder template to render the atom, called index.atom.builder. Inside this builder template, I'd like to render one of my existing html partials, to put in the atom:content element, perfectly normal atom thing to do. xml.content :type => "text/html" do xml.text! render(:partial => "my_thing") end The problem is that the template for my_thing is my_thing.html.erb. And since we're somehow in an xml 'context', the render call doesn't find it, it complains that no template could be found. If I change it to render(:partial => "my_thing.html.erb"), it works... sort of. Because it turns out THAT partial calls OTHER partials, and all of THOSE partial calls would also need to have ".html.erb" added to them. This is getting messy. Is there some better way to take care of this that involves sweet-talking Rails instead of fighting with it? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: cache logic in js_include_tag and stylesheet_link_tag?
Robert Walker wrote: > Jonathan Rochkind wrote: >> Is this a bug? Or is this expected behavior? Is there something I'm >> missing? Under what circumstances is the cached file supposed to be >> regenerated? If the last-modified timestamp changes on one of the >> included files, will it be regenerated? Will it EVER be re-generated? > > I see the same behavior, and I basically use the same solution. Probably > not a bad idea to add a step to your Capistrano (or whatever deploy > tool) to delete those files on each deployment. Thanks for the response. I'm thinking this is a bug, and I'll try to go ahead and file it in the tracker, although I lack the Rails fu to fix it myself. In the absence of a fix, could also add something to your Rails app startup routines to delete the files, to work regardless of Capistrano use or not. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] cache logic in js_include_tag and stylesheet_link_tag?
So using the magic :cache argument to combine multiple CSS or JS files into one cached file, using stylesheet_link_tag or javascript_include_tag respectively... I sort of figured that if the arguments to the function changed, including different files the combined cached file would be re-generated. This does not seem to be the case. javascript_include_tag "a", "b", :cache => "my_key" Stop application. Edit the code to be: javascript_include_tag "a", "b", "c", :cache => "my_key" Restart the application. Run it. The combined cached my_key.js file still only includes "a" and "b", the cached file was not invalidated when I added "c" to it. I had to go and find the file and rm it myself. Is this a bug? Or is this expected behavior? Is there something I'm missing? Under what circumstances is the cached file supposed to be regenerated? If the last-modified timestamp changes on one of the included files, will it be regenerated? Will it EVER be re-generated? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: rspecs for a rails plugin
Ho-Sheng Hsiao wrote: >> The one thing I'm still definitely still not getting to work right is >> auto-loading of classes. Maybe because "RAILS_ROOT" for the >> plugin_test_helper ends up being my_plugin/spec/app_helper -- but my >> classes are all in my_plugin/lib and my_plugin/app and such places. > > I don't know if you've seen this: > http://railsguts.com/initialization.html > > Browsing through the plugin_test_helper code, they have some hooks to > modify that initialization process, so that might be a way. The question is why the plugin_test_helper code hooking into the initialization process isn't actually _working_ to autoload the classes in my plugin! Well, I guess I can poor through the code. It's odd to me, because I wouldn't think switching out Test::Unit for rspec should effect that at ALL, I can't figure out how this works for anyone if it's not working for me. Oh well, that's why they call it debugging I guess. [I just want to get to _writing my code and tests_, not be spending all this time on infrastructure! Still surprised that this isn't a common problem someone else has already solved.] -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: rspecs for a rails plugin
Thanks Ho-Sheng, that helps. I think I'm actually getting there, starting with the plugin_test_helper, but modifying it for Rspec, as you had done. It's not THAT hard, and maybe once I fully figure it out, I'll try to submit it back to plugin_test_helper. (I don't know how I couldn't find plugin_test_helper in my own googling, showing me that was incredibly valuable thanks!) The one thing I'm still definitely still not getting to work right is auto-loading of classes. Maybe because "RAILS_ROOT" for the plugin_test_helper ends up being my_plugin/spec/app_helper -- but my classes are all in my_plugin/lib and my_plugin/app and such places. Maybe I can get around this just by setting the Rails load_paths in my spec_helper.rb? Does that make sense? I wonder how the ordinary Test::Unit version of plugin_test_helper handles that, it seems like it would be a problem for it too? [Just resetting RAILS_ROOT to be something else does NOT work, because of all the bootstrap code in my_plugin/spec/app_helper that is the whole point and DOES need to be in RAILS_ROOT]. What I'm doing: My plugin actually DOESN'T use ActiveRecord (yet). In fact it doesn't use _very_ much of Rails at all, but does use a _bit_ here and there (a couple views you can use in your app if you like). But even without testing the Rails functionality, the lack of auto-loading immediately tripped me up. And then I realized that if I wanted to test the tiny bit of AR functionality that is in there, THAT was going to trip me up when I got to it. And really, in general, I'm going to be writing several plug-ins. I want to figure out something that will Just Work for a Rails plugin, so I don't _need_ to think about _exactly_ what the dependencies are each time (and as the app changes), I can just set it up with a "Rails test environment" and write my tests, and go. I need test running to be as easy as possible so I will actually write them. :) So I think something based on plugin_test_helper, retrofitted for spec instead of Test::Unit, is indeed the key to that -- if I can just figure out the right way to get autoloading working! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: rspecs for a rails plugin
Ho-Sheng Hsiao wrote: > I have this exact problem. I'm refactoring the Foreigner gem and it > has some dependencies against Rails. I originally took > plugin_test_helper and attempted to make it more rspec compatible > before I realized that I did not need to load the full Rails stack. I > only needed ActiveSupport, ActiveRecord, and ActiveRecord::Migration > to run my tests. I have those things loaded in the environment. Ah, I see you are not actually using plugin_test_helper, on a re-read. Can you explain what you mean by "I have those things loaded in the environment". You load them in the environment how? We're not talking "Rails app environment", because there is none in your tests of the plugin, right? So are you just specifically loading the parts of Rails you need loaded in tests in your test code? require rubygems, require active-support? Or something else? Without Rails there, my _own_ classes don't seem to autoload, like they do in Rails. How are you loading all your own classes in so classes that reference each other can be tested? Even if I wanted to just "require" each one, one by one -- circular dependencies seem to cause a problem with that. Which the Rails autoloader somehow gets around, but I don't know how to do it myself for testing without Rails. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: rspecs for a rails plugin
Ho-Sheng Hsiao wrote: > You might want to check out plugin_test_helper to see how it gives you > callbacks to patch into the environment and initialization process, > and setting up different kinds of fake rails root. Thanks for the pointer to plugin_test_helper, I will try that. Somehow my googling hadn't come up with it. Ho-Sheng, is this actually working for you? You are having success with plugin_test_helper and rspec and a rails plugin? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] rspecs for a rails plugin
I have a Rails plugin, which is application independent, but depends on Rails, to be installed in a Rails app. (I have not yet converted it to a gem, but plan to eventually, and I'm not sure if that would change the answer to this question). I'm having trouble figuring out how to set up rspec on this plugin. The rspec environment needs to at minimum "auto-load" all the classes in the plugin itself (as a Rails env would do anyway), and ideally auto-load Rails too for the couple places in the plugin that depend on Rails classes. But it shouldn't depend on any _particular_ Rails application, as this is an independent plugin. Is there a trick for setting this up fairly simply so rspec will work? All I've been able to find googling is pretty old instructions/advice that doesn't seem to work quite right on contemporary Rails 2.x systems. Surely this is something other people have done? Thanks for any advice. Jonathan -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: no newline at end of partial view?
Jeff Cohen wrote: > My (wild) guess is that it's actually your ERB tag that's adding the > newline. > > You can use a minus sign as part of the closing ERB tag to indicate > that you don't want the newline: > > <%= render :partial => 'blah' -%> Aha, good point! I think you're right. In general, for very white-space-dependent ERB partials, I'm finding it tricky to get the white space right. Are there any special tricks people have in general for controlling whitespace while still leaving readable views, other than <%- and -%>. I know about those. But even with those, I'm finding I have to jam html tags together in order to get the whitespace I want. Hmm, I just thought of one. Instead of an actual literal: content in the html, which leaves no good way to control output whitespace without also making the HTML kind of hard to read, I could use: <%- tag("div") do -%> <%- "content" -%> <%- end -%> Which lets me exercize complete control of whitespace supression without actually having to eliminate it in my source. Does that make any sense, or is it completely ridiculous? It's still kind of hard to read, but in deeply nested html, still not as hard to read as "lots of stuffmore stuffmore stuffstuff" all jammed together without whitespace, because I don't want any whitespace in the output. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] no newline at end of partial view?
I have a view partial that is used to render a small block of HTML content. Because of where it's going to be placed in the HTML, it's important that it not begin or end with any HTML whitespace. But making a sample view partial that contains nothing but a simple string, just to test things out -- when rendered it seems to still end with a newline, which is of course HTML whitespace. Even though there's no newline in the html.erb file. Is there any simple way to make a partial view render with no newline at the end -- or the more general question, what I'm really after, with no HTML whitespace at the start or end of the partial view content? Thanks for any advice. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] use ActiveSupport::Deprecation myself?
So I have a plugin that is shared by many people. I'd really like a good way to mark certain methods as 'deprecated', that will be disappearing in a future version. I noticed that ActiveSupport::Deprecation seems to already include such things, and is used internally for marking Rails code as deprecated. But would it make sense to use this myself? It seems to be lacking any public rdoc at all, which makes me a bit nervous, maybe I shoudln't use it? But seems like it would work. class MyOwn include ActiveSupport::Deprecation deprecate(:method_name) ... end Good idea? Horrible idea? Is there a better idea to be able to mark deprecated stuff in my own classes? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: sybase in rails2?
Aldric Giacomoni wrote: > You would most likely want to transfer all the data to a mySQL or > PostgreSQL database (possibly renaming the id fields to railsify the > whole thing) and then not touch the Sybase DB again. > > Maybe get a Windows box or VM, just long enough to do what you want > (30-day trial for Windows) ? Nice idea, but this is a legacy enterprise database used by other software, not so easy to abandon it. My new plan (not really related to this thread, but perhaps useful for someone thinking about these things) is to write a web service in Java (there is already plenty of java code to talk to this db) that provides just the information needed by my ruby app (not actually the entirety of the database, not even close, just a few pieces of info, almost entirely read-only, for a few specific use cases) -- and just have the ruby app consume the web service instead. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: sybase in rails2?
Aldric Giacomoni wrote: > Did you see how my original tutorial involves editing an SQL.ini file ? > Can you try that? Thanks, I believe that is indeed the key, and would work. But the complexity of getting this working (Two different compiled packages, confusing configuration, needing to configure connections outside of the ruby app itself, etc) is making me re-think my whole approach to accessing my legacy Sybase database. Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: sybase in rails2?
Jonathan Rochkind wrote: > I have no firewall in the way. Don't know if the software didn't compile > right or what. Sigh. Geez, it may be that the ruby sybase-ctlib oddly seems to have NO facility for specifying what port to connect to Sybase on? I think my Sybase might be on a non-standard port, 2025. I think the port isn't making it into the attempt to connect. How could this have been left out? Man oh man. Maybe I'm misinterpreting. But looking at the code in ruby sybase-ctlib, and can't find any way to specify a port -- which would give the ActiveRecord sybase connector know way to pass on the port info. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: sybase in rails2?
Aldric Giacomoni wrote: > I am hanging to the edge of my seat; like Tim Curry would say, shivering > with antici... pation. > Please let us know the next and hopefully closing chapter in the saga! Well, I'm afraid I still don't actually have a Sybase connection working. Trying to initiate a connection from AR, it waits like 20 seconds then reports "Connection Failed". I have no firewall in the way. Don't know if the software didn't compile right or what. Sigh. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: sybase in rails2?
Ha! I just got it to work! I had some cruft in ~/.gem. Deleted all that, finally it SEEMS to be working. Or at least I'm on to a new level. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: sybase in rails2?
Okay, I figured out my problem with the help of "ruby -e 'puts $:'". I had a number of site_ruby directories that LOOKED legit, but weren't actually in the load path, who knows. But it's STILL not actually working. So, no, Aldric, I can't show you in a simple ruby program how I'm connecting, because it's still not working, heh. But to get CLOSE to working, I had to: 1) Install the OpenTds libraries 2) Install the ruby sybase-ct libraries. That was the tricky part, and I _think_ they're properly installed now. 3) Then we go into to "gem install active-record-sybase-adapter", yes. And your ActiveRecord::Base.establish_connection example. Which for me, STILL, even now that I'm pretty sure I have ruby sybase-ct installed properly, just says: ActiveRecord::Base.establish_connection(:adapter => 'sybase') RuntimeError: Please install the sybase adapter: `gem install activerecord-sybase-adapter` (no such file to load -- active_record/connection_adapters/sybase_adapter) from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `establish_connection' And, yes, I have the gem installed. Beleive it or not, before I had the gem installed, it was a DIFFERENT error. Aldric Giacomoni wrote: > Alright; can you show me, in a simple ruby program, how you are > connecting? > Also, are you connecting to Sybase ASE? > Did you do something like this: > > gem install activerecord-sybase-adapter -s http://gems.rubyonrails.org > > require 'activerecord' > > ActiveRecord::Base.establish_connection( > :stuff => more_stuff ) > ? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: sybase in rails2?
Aldric Giacomoni wrote: > Mine are in C:\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt > You probably have some i686 or i386 or i686-gcc directory there, instead > of msvcrt. Awesome, thanks, I'm on unix (Red Hat Linux), but this gave me some ideas to translate to the analagous location. I had TRIED putting them in /usr/lib/ruby/site_ruby/1.8/lib. That did NOT work. (I wonder what this dir is even doing there -- it was already there, I didn't create it -- and what it's for? Just to mislead me into making a reasonable but wrong guess about where to put stuff! ) I moved them to /usr/lib/ruby/site_ruby/1.8/x86_64-linux/ bah, still does not work. How very annoying. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: sybase in rails2?
Aldric Giacomoni wrote: > If I have time soon, which, sadly, is unlikely, I will try to get this > working on an Ubuntu machine. I believe you're right, and setting up > ctlib will help you out. Let me know what works, in the end, and I'll > put that on my blog as well - because you're right, this is very sadly > underdocumented. I _think_ I've got ctlib properly compiled (against freetds rather than Sybase's own libraries, no less). but I can't figure out where to PUT the products of the compile. the ctlib readme says: " Please copy sybct.o sybct.so sybct.rb sybsql.rb to somewhere of $LOAD_PATH." I am not sure what that means. Can't figure out where to put those files where a Rails app will find them, and << require 'sybsql' >> (a line in the AR adapter) won't just say "no such file to load". Any ideas? It's odd that sybase ctlib isn't simply a gem in the first place. That would be a real service, if you wanted to make it into a gem. Although compiling it is still going to require some manual attention to the extconf.rb file depending on where your sybase client libraries are. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: sybase in rails2?
Yeah, that helped a little. The key is clearly that the AR sybase adapter depends not only on sybase client libraries being installed, but also on the ruby sybase-ctlib being installed. http://raa.ruby-lang.org/project/sybase-ctlib/ Kinda tricky to get that installed, but at least I know what I've got to do now. All of this stuff is awfully underdocumented, hopefully this thread will help someone. Aldric Giacomoni wrote: > > I've never had to suffer through doing this in Linux, but I had to > suffer through doing it in Windows. > Maybe this can help you a little? > http://trevoke.net/blog/2009/09/11/connecting-to-sybase-with-rails-on-windows-xp/ -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] sybase in rails2?
Has anyone actually gotten the activerecord-sybase-adapter to work in Rails2? I can't seem to, and can't figure out why. I am on RedHat linux. I have the sybase client libraries installed, I have the adapter installed. After installing the patch at https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2455-update-for-sybase_adapter#ticket-2455-4 to get a slightly better error message, my error message is now, well, not slightly better at all. RuntimeError: Please install the sybase adapter: gem install activerecord-sybase-adapter (no such file to load -- active_record/connection_adapters/sybase_adapter) from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `establish_connection' Yet of course I have the adapter installed, it's just raising for some reason and this is what AR is telling me. I can't quite figure out what to do next. If anyone's actually gotten this to work on RHEL/Rails2, some tips would be much appreciated. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Controllers reuse or the way to reuse code along with views
Evgeniy Dolzhenko wrote: > > 3. Now I would like to have some super-method available at fixed URL > which will decide based on user settings which page to serve to the > user and call the appropriate controller. Personally, I would just write a controller that, after choosing the proper controller, just redirects to the URL for that controller. Any reason not to do that? > But this in my thinking brings another question - how to reuse just > code along with views? There is Cells plugin > http://github.com/apotonick/cells_examples/tree/master but I'm sort of > wary about bringing this in, especially since ActionControllers > already have what I need, i.e. the code with attached views. > > Moving the shared code to the module will work but only to the some > extent since there will be no conventional place for templates, no > simple way to define filters, etc. I'm not quite sure what you mean? There's no official built-in way to re-use code amongst controllers. But you can use any OO technique you want. Sure, you can put it in a module. Since you'll be including the module in existing controllers, conventional place for templates and filters etc will remain pretty much the same. Code in a module ends up getting executed 'as if' it was in the class that included it, right? It'll still look for templates in the same places as usual. If you have views shared between different controllers, just make a 'shared' sub-dir in your views dir, and refer to the template specifically as 'shared/template_name' instead of just 'template_name'. Or you can call it anything you want, not just 'shared'. This technique works for sharing view templates between controllers regardless of whether you need to share logic between controllers or not. I think I'd use a module for shared code between controllers. You could also use a common superclass for multiple controllers, but I don't think I'd do that. You could also put common code in an entirely seperate library class, that the controller gets a reference to: @more_controller_logic = MyClass.new ; @more_controller_logic.do_something. Depending on what it is you want to do, that may or may not be convenient. I think a module is probably what you want. If there's a specific kind of logic you want to put in your module shared between controllers that for some reason doesn't seem to be working... try asking with that specific example. I think a module should work fine. Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] render mutates locals hash?
If you pass a locals hash into render() ... why would Rails mutate that hash, adding things to it? This seems awfully odd to me. Could have something to do with calling partials inside partials, which I am doing. Does the locals hash 'inherit' to the 'inner' partial? That's kind of odd. I just traced a weird bug in my app down to this -- I was storing locals in an actual hash data structure, instead of using an anonymous hash, and wasn't counting on rails changing in between calls! By "freeze"ing the thing that I didn't expect to get modified, I could get this stack trace pointing to what's doing the modifying, but I haven't looked at it yet. /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/partial_template.rb:48:in `[]=' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/partial_template.rb:48:in `add_object_to_local_assigns!' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_view/partial_template.rb:9:in `initialize' -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: autocomplete fill in text fields
Actually, sorry, that page indeed didn't answer your question. Try this one though. Googled for "rails autocomplete multiple values" http://www.wayne-robinson.com/journal/2006/11/11/multiple-values-from-scriptaculous-autocomplete.html This is not something I've done myself before though, sorry. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: way to divide long article and store in database
Jian Lin wrote: > I wonder if a Ruby on Rails developer has encounter this before: suppose > it is a long article (say 100,000 words), and I need to write a Ruby > file to display page 1, 2, or page 38 of the article, by > > display.html.erb?page=38 > > but the number of words for each page can change over time (for example, > right now if it is 500 words per page, but next month, we can change it > to 300 words per page easily Why divide it in the database? Store it one field in the database, and when you fetch it from the database just perform the logic to find page=38 and then display that. If actual testing indicates that's too slow with the actual quantity of data you expect, then you'd have to perform a word-boundary calculation on inserting the value in the db, and store the results as an 'index' to the text somehow. Either way, I don't see any reason to actually split up the text file in the db. Unless you want to let the user _search_ for, say, word X on page N of the text. But then you're getting into complicated enough text searching land that I'd investigate using something like lucene/solr to index your text, instead of an rdbms, and seeing what support for page-boundary-based-searching eg lucene/solr have. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: autocomplete fill in text fields
Chris Habgood wrote: > ok where do I do that at? Have you tried googling for instructions? When I try: http://www.google.com/search?q=rails+autocomplete The first hit is: http://codeintensity.blogspot.com/2008/02/auto-complete-text-fields-in-rails-2.html Seems to me to tell you exactly what you are asking. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: ActiveRecord changes Logger formatting
Frederick Cheung wrote: > probably because activerecord requires activesupport and activesupport > does > > http://github.com/rails/rails/blob/669fd84910586d4c791b6f5bf4320f68ac7845aa/activesupport/lib/active_support/core_ext/logger.rb > For what it's worth, I share the original questioners general unhappiness with Rails default logging format. It's possible to customize that without too much code, although somewhat more confusing and under-documented than one might wish, and also seems to change slightly from one Rails version to the next, for whatever reasons the precise hooks into Rails logging mechanisms seem to be somewhat unstable. Here's how I customize logging in a Rails 2.1.2 app, choosing to use the Rails2 default "BuferredLogger" for what (I assume) is better efficiency in disk writes, but with my own output formats. Anyone feel free to let me know if there's a better way, or if this is easier in subsequent Rails versions. But it's not too hard (once you figure it out, which took me a bit of playing around). In my lib directory, a sub-class of the BufferedLogger that actually accepts a formatter, as the standard BufferedLogger (at least in 2.1.1) oddly does not: http://umlaut.rubyforge.org/svn/trunk/lib/umlaut_logger.rb Then in environment.rb, set the logger and it's formatter: require_dependency 'umlaut_logger' severity_level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) log_file = File.join(RAILS_ROOT, "log", "#{RAILS_ENV}.log") our_logger = UmlautLogger.new(log_file, severity_level) our_logger.formatter = lambda do |severity_label, msg| time_fmtd = Time.now.strftime("%d %b %H:%M:%S") preface = "[#{time_fmtd}] (pid:#{$$}) #{severity_label}: " # stick our preface AFTER any initial newlines msg =~ /^(\n+)[^\n]/ index = $1 ? $1.length : 0 return msg.insert(index, preface) end config.logger = our_logger -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Same table, multiple DBs?
Brian wrote: > > Is there any built-in way to handle this in rails (or a popular plugin > that can do this)? My very initial investigation seems to indicate a > specific table can be stored on another DB, but that ALL of the rows > are stored on that DB. I can't split this up across multiple servers. As far as I know, you're right that you can only specify a different DB on a per-model basis. But you could make sub-classes of each of your models, one per each db, and then specify the different DB on each of those sub-classes. But then when doing a fetch, you'd have to choose the right model to do the fetch from -- but of course, that's kind of the point of why you can't have more than one db on just ONE model -- how would Rails know what DB to go to when you simply tried to do a Model.find on that model? I'm not really feeling confident that the architecture you're proposing really is the best solution to scaling up, but if you wanted it, I think ActiveRecord could support it in that manner -- by first writing your models, and then providing N sub-classes of each model you want to 'partition' to N databases. You could even provide some code to do this 'dynamically', you wouldn't need to (and wouldn't want to) actually hand-code a separate file on disk for each model. All the associations defined on the 'base' model would need to be re-defined for each model sub-class to use the appropriate destination model-subclass. This could also be done in an automated dynamic way. And then you'd need to provide some helper methods to figure out _which_ model to use for a given fetch (Model.find) operation. I'm not aware of any plug-in that already does this. I'm not sure it's a good idea, like I said, but I'm no expert. I think you'd have to write the logic yourself, but I think it's perfectly do-able within ActiveRecord's architecture. But no doubt it will end up somewhat more complicated to get working right than it seems at first, such things always do. Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: shortcut to call js function
Mk 27 wrote: > However, "getting the inline js" out will inevitably increase the actual > codebase of the project as whole, because you will have to add *more* > lines to your external scripts than you would have used in the page > source by inlining in *at least some* (if not quite a few) cases. All I can say is that in the (non-Rails) project where I'm consistently using unobtrusive JS, this has not been my experience. It hasn't led to any more lines of code. This does in part depend on your HTML DOM being fairly well structured with good classes and id's. In my experience, once you learn how to do it right, it's no more lines of code to maintain, and forces you to have better-structured HTML to boot, which is an added advantage. But there is a bit of a learning curve, sure. Now, if you had to give up all the Rails helper methods (that are essentially dynamic js-code-generators), then THAT would lead to more code. I wouldn't want to do that. So I'm going to check out the UJS Rails plugin that Fred helpfully alerts us to. But to each her own. I was gonna try to look at your example to show you a short concise unobtrusive JS version that would do the same thing, but I don't understand the case quite well enough and don't feel like spending the time trying to just to make a point. But my experience leads me to be confident it would be possible. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Combine if and do in a single line?
Frederick Cheung wrote: > {} binds more tightly than do..end - in some cases this can lead to > your block being passed to the 'wrong' method: Interesting, makes sense. Personally, that's one reason I don't like making method calls without parens, or doing anything else that relies on non-obvious order-of-evaluation-binding just to save a couple of parens. foo( bar {} ) or foo( bar do end ) will both do the same thing. Although the latter is kind of weird style, if I need a multi-line block for bar, I'd personally just use a temporary var instead. result = bar do end foo(result) But everyone's got their own style, I guess. Of course you COULD use {||} with multi-lines too, but it would also be stylistically weird in my opinion in that case. foo bar {|a| stuff more stuff } That's just weird. And if I DID it, I'd still want to put parens in around foo's argument, which would make it even weirder looking. Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Need help : How to render HTML inside of a JSON request
Bah, you know what, ignore me. I just realized you're asking about _partial_ specifically, and now I realize the solution isn't as clear. And I know why you might want an html partial in a js response, because I do that myself. :) And now I see that I'll have to deal with this when I upgrade to rails 3 too. I suspect you just have to change the partial like you say, but I don't know if that would be considered a bug or not. Okay, I'm done in my marathon of answering quesitons in the listserv, now that I've started giving bad answers. :) -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Need help : How to render HTML inside of a JSON request
RFine wrote: > > render :partial => 'comments/partial_name' > > If I change it to : > > render :partial => 'comments/partial_name.html.erb' > > and it works. It appears as though the fact that the call is a JSON > request from the client is causing the render engine not to search > for .html and .html.erb in the path, thus they fail. You got it. Why are you returning .html from a ajax/json request from the client, anyway? Generally, ajax requests from the client get back javascript (or specifically json), not html! Rails is trying to help you with this general case, because you can have the same action that will return partial.html.erb if it's an html request, or partial.js.erb if it's an AJAX request. I forget exactly how Rails determines when the format is js, but I know if you're using any of the Rails helper methods for ajax callbacks, they definitely include a query param to tell Rails what's what. So you can change the render call like you say. Or you COULD rename the partial in the old way partial_name.erb, so Rails will use it for any format request. But that's kind of weird (and now i'm not entirely sure it'll work). Or you could reconsider why you want to return HTML (rather than js/json) to a js request in the first place. Or you could take a look at respond_to to see how you can return different views for different request types. http://api.rubyonrails.org/classes/ActionController/MimeResponds/InstanceMethods.html#M000368 -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: How to keep persistent socket connections?
Steve Hull wrote: > Yeah, that didn't work because caching the connection makes it > immutable, which means you can no longer write data to it. But you know > what I think *will* work? Storing the connection(s) as class vars. So > I'm trying that next. I will report back here afterward for anyone who > might be interested. I'd use a singleton object (ruby Singleton module lets you do this easily, or it's easy enough to do yourself) that encapsulates logic and state for your 'connection pool', rather than class variables. But you're on the right track. Note though that you've got to make sure all your logic (in this case in that hypothetical Singleton object), is concurrency-safe, if your rails app can possibly be deployed in any kind of a concurrent-request environment (or if you plan to create Threads yourself in your rails app, but hardly anyone ever does that). You could look at the newish Rails 2.2 ActiveRecord ConnectionPool for a model, since it's doing basically what you want, but specifically for db connections. The ConnectionPool code might just end up being too confusing and complicated though, since it has to deal with Rails backwards compatibility issues and stuff. I haven't actually looked at the ConnectionPool code myself much yet. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Can I update session variable in a new thread?
>> But it is do-able, although not easy, I don't think you can get away >> with just trying to access the session array itself in a thread that's >> out of the request loop. Sorry, this is a topic of interest to me that noone else is ever interested in talking about. PPS: REALLY, if you decide you want to set off a thread that will persist after the response is returned, despite the general pain in the neck of doing that cause neither ActiveRecord nor MRI 1.8 Ruby are entirely happy with it (but it's still possible if you take the right precautions)... AND... you need that thread to store state that later requests can access Consider just storing it in the db as an ActiveRecord rather than trying to put it in a session. All in all easier to deal with, at least if your thread already was using ActiveRecord anyway (which supplies it's own headaches). Worth considering, it's a trade-off as to what sort of headaches you want to deal with. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Can I update session variable in a new thread?
Jonathan Rochkind wrote: > > But it is do-able, although not easy, I don't think you can get away > with just trying to access the session array itself in a thread that's > out of the request loop. I'd add it's do-able ONLY if you are using a server-side session store. NOT if you are using the cookie store that's the new Rails default. With the cookie store there's simply no possible way to write to the session outside the request loop. So if you want to write to a session in a thread, you'd have to wait() on the thread before returning from your action, which might defeat the purpose you were trying to use the thread for in the first place. Also, if you are planning on using ActiveRecord in this thread, you've got to make sure to do a few other things to ensure your AR calls are thread-safe. Things which change slightly in different Rails versions, as Rails community has changed it's consensus on what sorts of threading are 'supported' in what ways. And ALSO, even aside from AR, I learned the hard way that (at least if you're using the standard 1.8 MRI ruby interpreter), if you want to send a thread off and let it keep going outside the request-loop, you'd really better set it's priority to -1, or it's going to end up interfering with your response being returned even though you don't think it should. Contrary to popular belief, it IS possible to do concurrent programming like this in Rails, in all versions. But it's a big pain in the neck. Don't do it unless you really have to (which I think I do in my situation), try to find another solution if possible. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Can I update session variable in a new thread?
Sudhi Kulkarni wrote: > Then in one of the periodic update methods if I access the > session[:executing] it is not updated to "done". Is there a problem if I > try to update session variable in a different thread? Actually, this is precisely what I was trying to do in another thread here where Fred graciously helped me too. I'd advise NOT trying to use the session array Rails gives to you, but instead just telling the thread the sessionID, and ten doing all the session access yourself manually. That's what I'm doing. It's not TOO hard, although it inconveniently changes for Rails 2.2 vs. pre-Rails 2.2. See this: http://www.ruby-forum.com/topic/184782 And see if it makes any sense to you, or still seems worth it to you when you see what you must do. :) But it does seem to be working for me, with some basic unit tests. There's sadly one more added wrinkle with regard to race conditions when you start to deal with sessions like this, that can result in the main action over-writing the session data the thread tries to write, or vice-versa. I have a hacky way to minimize (although not totally eliminate that), that is Session-store agnostic. You can totally eliminate it if you're willing to hack the particular session store, as I believe Fred has also done for the AR store, but I think this is quickly getting beyond what you hoped would be an easy answer. But it is do-able, although not easy, I don't think you can get away with just trying to access the session array itself in a thread that's out of the request loop. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: query on Ruby array
Conrad Taylor wrote: > An Array instance can respond to both count and size methods. If you > use > size the method with a counter > cache column on the has_many side, you can cache the total. You can't possibly mean an Array, because an Array doesn't know anything about going to databases or cacheing. An Array is just a list of stuff. You might mean an ActiveRecord Association collection object, which behaves a lot like an array, but also has some 'magic' ActiveRecord behavior on it. The fact that, as far as I know, there's no actual class name for this AR association magic collection object, makes things rather confusing, I agree. I think it's just some proxy methods singleton-added to an Array, leaving us without a good name to call what it is, making things confusing. Or if it really is a class, I don't know what it's called cause it's not mentioned in the docs. This is a kind of a-bit-too-clever ruby hacking that Rails, IMHO, uses sometimes when it doesn't really have to, making things somewhat more confusing than they need to be. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Combine if and do in a single line?
Mario Gr wrote: > Is there a way to combine if and do into a single line? > > items.each do |item| if current_user.admin? > #do stuff > end > > Thanks! Freddy Andersen wrote: > items.each { |item| item.stuff? } if current_user.admin? Which you actually COULD write like this too, but I'm not sure if it would be considered easily readable: items.each do |item| #do stuff end if current_user.admin? The {| | } and the 'do' syntaxes are interchangeable in all ways. More of a Ruby question than a Rails one. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Rails: concurrency question
Steve Hull wrote: > BUT Rails is essentially single-threaded (only a single request > processed at a time), so if I have only a single call to my singleton > instance method per http request, then it should be impossible to get > concurrency problems with it. Right? > It's actually possible to write various kinds of concurrent code in Rails -- it really ALWAYS was possible to have some concurrency, but not concurrent request handling, and whatever concurrency you added you'd add yourself. But in more recent versions of Rails, even some concurrent request handling is supported. allow_concurrency!. And perhaps Passenger in certain modes as Roderick says, I'm not familiar with Passenger. But you're basically right about the 'ordinary' mode of Rails execution, that only a single request will be processed at a time. This is increasingly not the only option for Rails though. But, yeah, you're also right that if you had Rails executing in a mode that allowed concurrent request handling, you'd need to take care of making sure your singleton object itself is concurrent-access safe -- the singleton pattern will take care of _instantiation_ of the Singleton object being concurrency-safe, but can't take care of it's own internal logic. So you can either do that -- or you can note in comments that this thing isn't concurrency-safe, and shouldn't be used in a concurrent-request environment. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: shortcut to call js function
Mk 27 wrote: > You have hit a paradox by saying that you want to use prototype, etc. > but you do not want to see any js calls in your html files. I do > understand it is an explicit goal of rails to minimize the Look up "Unobtrusive javascript". Eg http://en.wikipedia.org/wiki/Unobtrusive_JavaScript You can keep almost all javascript out of HTML except for simply loading external script files which then attach the appropriate javascript behaviors where necessary. I have become quite enamored of this approach, I think it both facillitates more maintainable code with proper seperation of concerns, as well as facillitates better 'accessibility' (not just for non-js user-agents, but the possibility of swapping in _different_ js functionality for different contexts and/or user-agents). And as I become more enamored of this approach, I'm more and more unhappy with Rails js helpers, which definitely don't follow it. Curious if someone in the Rails community has figured out a good way to accomplish what Rails helpers do (controller logic in the controller instead of view, DRY for js idioms, etc) but in an "unobtrusive" idiom where no JS (apart from
[Rails] Re: manual access to session data outside of request?
> Frederick Cheung wrote: >> >> Struct.new('FakeSession', :session_id) >> fake_cgi_session = Struct::FakeSession.new('some session id') >> >> session = WhateverSessionStoreClass.new(fake_cgi_session) >> session.restore >> Okay, pre-Rails-2.2, if you want to fake a session and you want to have it work to create a new session with that ID even if one doesn't currently exist, and you sometimes use an ActiveRecord session store (phew), then instead of simply using a Struct to create a duck-typed fake session, you need something that will implement new_session too, still using the same session_id. class FakeSession attr_accessor :session_id def initialize(a_session_id) self.session_id = a_session_id end def new_session return self.session_id end end -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: manual access to session data outside of request?
Frederick Cheung wrote: > 2.2 is a bit easier actually - > > Struct.new('FakeSession', :session_id) > fake_cgi_session = Struct::FakeSession.new('some session id') > > session = WhateverSessionStoreClass.new(fake_cgi_session) > session.restore > > Fred > Revisiting old history. Huh, I swear I had this working before in Rails 2.1, but I return to it to finish it off and now it does not. on the .new(fake_cgi_session) call, I get: NoMethodError: private method `new_session' called for # I probably just need to get my app working in 2.3, where this is all much more consistent and rational. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] check for existence of session without triggering one?
With the new session lazy loading -- how can I check to see if a session has already been created, and not trigger the creation of a session if not? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] optimistic locking with session store?
Okay, continuing in my project of abusing Rails horribly. It looks to me like even standard Rails sessions are subject to a race condition if the same session is accessed concurrently. Request1 checks out a session. Request 2 checks out a session, makes a change, and writes it back to the store. Request 1, still finishing up, makes a change, and writes the session back to the store... overwriting the changes Request2 made. So, if I'm using an ActiveRecord store... what happens if I just add a lock_version column to the model? But then I guess an exception will be raised from the innards of ActiveController somewhere. And it would be unclear how to recover from it. So that's not quite right. Has anyone come up with an optimistic locking solution for Rails session to get around this race condition issue? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: manual access to session data outside of request?
Jonathan Rochkind wrote: > Ah, but I guess now I have your sample code to _read_ a session. Do you > have any similar magic code to write it back out to the store? I guess I > can probably figure it out for myself now that I know the magic way to > fake a cgi session. Ha, I've made it work! Now I just need to do it for rails 2.3 too, to have it both ways. But here's the rails pre-2.3 version. Thanks Fred! Struct.new('FakeSession', :session_id) # Craziness to restore a session in Rails pre 2.2. Will most likely # need to be changed for Rails 2.2. fake_cgi_session = Struct::FakeSession.new('some session id') session_obj = ActionController::Base.session_store.new(fake_cgi_session) @session = session_obj.restore # Later, you've modified the hash and want to save it back to store? # just: session_obj.close You want to save something, just modify that hash, and then call -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: manual access to session data outside of request?
Frederick Cheung wrote: > the pre 2.2 way should work way back to rails 1.1, and possibly even > further back. Huh, then I might as well do it the actual legit way, and I guess I can now easily do this in a storage-agnostic manner for both pre 2.2 and 2.2. Nice, thanks for supplying that sample code Fred, after a couple hours looking through the Rails source I wasn't any closer to figuring it out for myself. Ah, but I guess now I have your sample code to _read_ a session. Do you have any similar magic code to write it back out to the store? I guess I can probably figure it out for myself now that I know the magic way to fake a cgi session. Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: manual access to session data outside of request?
Frederick Cheung wrote: > On 20 Apr 2009, at 19:31, Jonathan Rochkind wrote: > 2.2 is a bit easier actually - I must admit that my app is still in Rails 2.1 now, for annoying reasons that will make everyone tell me I'm doing Rails wrong again. > If you assume ActiveRecord store it's pretty easy. find the row with > the right session id, data is right there. Yeah, I think that's the way to go for now. I'd like to use ActiveRecordStore's own methods to serialize/unserialize the data, to not have my code depending on certain assumptions about precisely how ActiveRecordStore serializes, but I think that's do-able too. Thanks for helping me think this through. Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: manual access to session data outside of request?
Frederick Cheung wrote: >> Unless the specs for how to write a session store have changed in 2.3, >> it may be my code doesn't need to be different for 2.3. But if it does, >> I can deal with that too. >> > They did - had to rewrite a lot of that bit of my session store for > 2.3 > Thanks Fred. It actually looks like this would be fairly straightforward in 2.3. This blog post provides some hints: http://devblog.michaelgalero.com/2009/02/03/guide-to-rails-metal/ But my app is not yet working with 2.3 in general, and I'd like it to work with both. And in pre-2.3, it seems, from looking at the Rails source, that it would be REALLY tricky to do this. So now I'm thinking of another option. One would be storing this information in my own database models, keyed by Rails SessionID. But once I've done that, I've kind of duplicated the ActiveRecordStore. So another option would be writing my code to assume that the session store is an ActiveRecordStore -- if you make this assumption, instead of trying to write store-agnostic code, then accessing the info in pre-2.3 looks to be more do-able. And I could write code that works with either pre 2.3 or 2.3. Not sure what I'm going to do really. I need something keyed on sessionID that is accessible outside a Rails request, as well as inside a Rails request. If anyone else has ideas, feel free to share. Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: manual access to session data outside of request?
Frederick Cheung wrote: > The details have changed between rails 2.2 and 2.3, in 2.2 it was the > old cgi interface, in 2.3 it's the new rack interface - you'll need to > instantiate the appropriate subclass of ActionController::SessionStore This helps, thanks. Trying to look through the source and googling, I did discover that this changed very much between 2.2 and 2.3, I might need to write two versions of my code. But since there is an abstract model for a session store, it must be possible for me to access the session store and read and write session info without knowing about the black box internals. Once I've gotten the appropriate ActionController::SessionStore... what the heck do I do with it in order to read or write session data? Unless the specs for how to write a session store have changed in 2.3, it may be my code doesn't need to be different for 2.3. But if it does, I can deal with that too. Still having trouble figuring out what methods to call on a session store once I've gotten it to read or write data. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] manual access to session data outside of request?
So, given a sessionID, I have need to read and write the session stored information 'manually', from _outside_ an actual Rails request/controller. Readers, I know your first response may be to tell me I don't really want to do that. Trust me though, I really do, it makes sense for me in my case. I know this wouldn't work if you're using the new cookie session storage mechanism. But if you're using a server-side session storage mechanism, I'm thinking there must be some reasonable way to do this. But I'm having trouble figuring it out. I've tried looking through the rails source code to see how Rails reads and write session, but I'm having trouble finding the relevant code. I also figured, gee, since Rails allows pluggable session storage architecture, there must be an abstract description of what a session store must implement, and how to access it, and that might help me -- but I couldn't find that either. Anyone have any ideas or tips? I'd like a session-storage-implementation-agnostic (assuming it's a server-side method of storage) way to read and write the session hash from outside a Rails controller. Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: keep 404's out of my logs
Jonathan Rochkind wrote: > > Is there any easy way to tell Rails to keep [RoutingError, UnknownAction, > UnknownController] out of my logs? Or > put them in a different log? Or at least omit the backtrace (which is > not a useful backtrace, since it's to Rails internals and is always the > same for an UnknownAction or RoutingError). > > By the time rescue_action_in_public is called, it seems to be too late, > the thing has already been logged. Figured it out myself looking at source in ActionController::rescue.rb . I'll put it here for the archives. In Rails 2.1 (and hopefully 2.x in general), rescue_action_in_public is called by rescue_action. rescue_action also calls log_error, after calling rescue_action_in_public. It's log_error that writes uncaught exceptions to the log as fatal, with complete backtrace. So I can override log_error, and check the class of the error. If it's not a routing type error, call super. If it is, I can not log it, log it to a different logger, log it with a different severity, whatever. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: route to static resource?
Philip Hallstrom wrote: > You could add a catch-all route at the end that checks for > "favicon.ico" and then send-file the real favicon.ico back. Or to > speed it up do it using rack/metal. > > But if were me, I'd do it in apache. That will definitely be the > fastest. Woops, I forgot my real question. Right, I can do a catch-all like that (I actually did figure out a way to do that) -- but how do I have a rails route send back a static file? Do I need to create a method in application.rb for sending back the static file? Any way to tell a route to result in a static file? THAT was my original question! Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: route to static resource?
The problem is a catch-all route at the end would be AFTER the default map.connect ':controller/:action/:id' type routes. So weird routes that things like Google Toolbar and MS Word keep sending like "fake/notAnAction.gif" would not get caught by my catch-all, right? I guess apache is the way to go. Or, in another question I posted in another thread, figure out how to keep Rails from putting a backtrace in for these kind of errors in general. Haven't figured out where in Rails is actually generating that annoying backtrace in production.log in the first place. Philip Hallstrom wrote: > > You could add a catch-all route at the end that checks for > "favicon.ico" and then send-file the real favicon.ico back. Or to > speed it up do it using rack/metal. > > But if were me, I'd do it in apache. That will definitely be the > fastest. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] keep 404's out of my logs
So every time something requests something from my rails (2.x) app that doesn't actually map to a controller, I wind up with an error in my production.log. ActionController::RoutingError or ActionController::UnknownAction depending on the nature of the bad request. Is there any easy way to tell Rails to keep these out of my logs? Or put them in a different log? Or at least omit the backtrace (which is not a useful backtrace, since it's to Rails internals and is always the same for an UnknownAction or RoutingError). By the time rescue_action_in_public is called, it seems to be too late, the thing has already been logged. Thanks for any ideas! -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: route to static resource?
Rob Biedenharn wrote: > Do you have something in your layout that says to find "favicon.ico" > that could just be changed to "/favicon.ico" perhaps? Nope, it's nothing in my layout anywhere. It's Google Toolbar acting up for some reason. Apparently others have seen it too: http://www.google.com/support/forum/p/Toolbar/thread?tid=78479dcc02044f76&hl=en But still wondering if I can 'route' to a static resource, occasionally need that for other purposes too. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-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] route to static resource?
Is there any way to write a route that delivers a static resource? For some reason something (looks like Google Toolbar according to the user-agent string) is requesting favicon.ico at all sorts of weird places, not just at the root location where favicon.ico belongs, but at /someAction/favicon.ico, etc. I'd like to direct these all to the actual favicon.ico, to keep them out of my error logs. If I can't do it in routes, I guess I can do it in apache. Thanks for any help! -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: what does config.threadsafe! actually do?
Aaron Baldwin wrote: > There is some good information right in the rails 2.2 release notes > along with links to blogs with more information. > http://guides.rubyonrails.org/2_2_release_notes.html#_thread_safety Thanks Aaron. I definitely checked that out before posting, but it (and it's links) don't have quite enough information for me. They don't really say what config.threadsafe! _does_, except for allow concurrent request handling. Guess I'll have to dive into the source at some point. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] what does config.threadsafe! actually do?
Does anyone know what config.threadsafe! actually does, what effect(s) it has? I'm even sure where to go looking in the source code for effects of a config variable like that, but if someone has source to recommend, I'll give it a shot (although I sometimes have trouble comprehending AR source, I must admit). I know it tells Rails to do concurrency request handling. Okay, so far so good. But I suspect it does other things to to them make Rails behave differently to support concurrent request handling, rather than simply remove a mutex around the event loop or whatever. I ask this because, while I'm not actually interested in concurrent request handling (don't need it), I _do_ use threads in my Rails app for other purposes. (Dealing with long-running processes, dealing with talking to slow external web services). I'm actually surprised that nobody else seems to have a use case for this, but in my app it's pretty crucial. So I'm trying to figure out what Rails 2.2 can do for me, and how I'll have to change my Rails 2.1 code to deal with it, etc.. The changes around supporting threading more intentionally are potentially good, but the only documentation or writing I can find on it (and very little of that) assumes you are interested in concurrent request handling. Since I'm not, I don't neccesarily want to call config.threadsafe!. But I'm wondering if there are side effects of config.threadsafe! that I might want to trigger myself, to make Rails happier about handling multiple threads (possibly with AR) even without concurrent request handling. Anyone have any info to point me to? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] threading, returning from action method, blocking
So, in a Rails 2.1 app, I'm doing a bit of threading. Even though this isn't exactly recommended, it seemed to work (taking care to use ActiveRecord in a thread-safe manner, or not at all in threads). But I've noticed something odd. The main thing I do with a thread, is in an action method (ie, an action in a controller), right before returning from the method, I start a thread to do some finishing up clean-up in the background. Since this cleanup is potentially a lengthy process, the idea is that this won't prevent the response from returning to the browser. def someAction # some stuff Thread.new do #background(?) stuff end return end The expectation was that the response would be returned to the browser immediately, it would not wait for that Thread to execute. It wouldn't matter how long the code in "#background(?) stuff" took to run, the Thread would be started, and then the next statement would be read after the thread, ending the action method, proceeding with the view, without waiting on the Thread. Everything could be asynchronous. However, I've recently noticed that this doesn't seem to be the case. The stuff in the Thread _is_ keeping the response from being returned. If I put a "sleep(10)" at the top of the Thread do body, then everything clears up--it doesn't wait an extra 10 seconds for teh response, THEN the response is returned immediately. But without this, it seems that something in the Thread is blocking the rest of the Rails process to return the response, not for the entire time it takes it to run, but... for some time. Does anyone have any ideas what's going on, or how else to accomplish this? (Please don't same BackgrounDRB). Thanks, Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: url_for and ampersand escaping?
Hassan Schroeder wrote: > On Fri, Jan 2, 2009 at 4:08 PM, Jonathan Rochkind > wrote: >> >> ... url_for [helper method] seperates query parameters with >> & url_for the controller method does >> not. > Why "unpredictable"? HTML requires ampersands to be escaped, > as part of URLs or otherwise. > > A URL in plain text format, though, should not have ampersands > escaped. I knew that a URL in xHTML required ampersands to be escaped like that, even in an . I did not know that a URL in standard (non-x)HTML required that. Really? Okay. But it's confusing in part because an ERB template isn't _only_ used for HTML. It can theoretically be used for creating any format, including plain text, right? And someone using an ERB template to create (eg) plain text is going to get tripped up there. In my case, I wasn't creating plain text, I was creating XML with an ERB template. Which should be a perfectly fine thing to do, right? Sure, you can use Builder if you want for XML, but you should be able to use an ERB template too, right? But this definitely isn't the first time I've been confused by the proper amount of escaping of an ampersand in a complicated data flow. I'm still not exactly sure if I fixed my bug in the right part of my somewhat complicated chain of data flow. I'd appreciate if you have any insight, Hassan. Here's what was going on: An ERB template was generating XML. It took the result of a url_for call, and put it through an XML-escaping routine, figuring that anything that was being put in XML should be put through an XML escaping routine. (Is this where I went wrong? Not sure.) So we wound up with XML who's source looked like /controller/action?foo=foo&bar=bar Is this correct or not? Not sure. Later in the program execution, this XML gets converted to JSON, and the JSON winds up looking like: some_url: '/controller/action?foo=foo&bar=bar'; This part was right, that is a proper JSON translation of the XML passed in, right, it un-escaped the XML properly, put it in JSON. Then, this JSON gets delivered via JSONP to some javascript (external javascript not generated by rails). The javascript gets that value in a variable, containing '/controller/action?foo=foo&bar=bar'. So far so good, it got the right value from the JSON delivered to it. Now, if that had been in HTML source for an , I guess the browser would have 'un-escaped' that before making the HTTP request. But it wasn't in HTML source, it was in a javascript variable. And when I passed this variable to my javascript routine to load the URL (AJAX-style), it ended up submitting a GET to the HTTP server that looked like this: GET /controller/action?foo=foo&bar=bar That wound up being caught by a mongrel-fronted Rails app, which did NOT turn that into query parameters foo => foo, bar => bar properly, it did weird things with that GET request. So. At what point did that code go wrong? At the moment, I've fixed my XML-generating ERB to _not_ escape urls generated by url_for. But I'm not sure that's right, it doesn't feel right. Or is it my javascript code that took a js variable containing '/controller/action?foo=foo&bar=bar' and made a GET of that literal string, instead of un-escaping it first, that went wrong? Or something else? I'm very confused. And, since ERB can be used to generate all kinds of formats, it still seems to me that the documentation should mention this feature, which would have gotten me to my present state of confusion several hours earlier---ah, but when I go look at the most recent rdoc ActionView url_for, I see that it was there all along, my fault for missing it: "When called from a view, url_for returns an HTML escaped url. If you need an unescaped url, pass :escape => false in the options." So good on the rdoc after all. Still somewhat confused as to whether I should be "double escaping" it in the XML or not. Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: url_for and ampersand escaping?
Oh boy, this was a crazy one. It wasn't url_for that was behaving differently. url_for on both servers seperates query parameters with & (url_for the helper method; url_for the controller method does not. I did not know this. Kinda confusing and unpredictable--and undocumented). But okay. I was then passing it through REXML in order to 'escape' it for eventual inclusion in some XML: xml_escaped = REXML::Text.new( generated_url ).to_s The difference between my two servers was ruby version, not Rails version. REXML is included with stock ruby (I didn't realize that either). REXML::Text that comes with ruby 1.8.5 will not 'double escape' & to & . I guess I'd consider that a bug, indeed. It probably should be double escaping something like that, if you pass it in escaped. REXML::Text that comes with ruby 1.8.6, on the other hand, WILL double escape that text passed in escaped. Wooh, what a mess. Jonathan Jonathan Rochkind wrote: > I have two different servers, with two different test rails apps, both > of which claim to be running Rails 2.1.2. > > On one of them, url_for in a view environment generates & in between > query parameters, instead of just &. On the other, it generates just &. > > Huh? I can't figure out why this is one way in one app that claims to be > Rails 2.1.2, and another in another. > > In neither one does url_for called in a controller context (rather than > a helper context) use "&" to separate query parameters, it just uses > "&". > > It's driving me crazy. Anyone have any idea what might be going on? > > Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] url_for and ampersand escaping?
I have two different servers, with two different test rails apps, both of which claim to be running Rails 2.1.2. On one of them, url_for in a view environment generates & in between query parameters, instead of just &. On the other, it generates just &. Huh? I can't figure out why this is one way in one app that claims to be Rails 2.1.2, and another in another. In neither one does url_for called in a controller context (rather than a helper context) use "&" to separate query parameters, it just uses "&". It's driving me crazy. Anyone have any idea what might be going on? Jonathan -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Rails 2 caching?
That does help, thanks. Sometimes I need fresh data within an action even. Or for my tests--should the sql querries be cached during tests? Is the semantics for what is cached when documented anywhere? I also discovered "ModelName.uncached do", which is helpful. But @individual_model.reload is good too, along with @individual_model.reset--although I'm not sure #reset will actually prevent re-use of the sql cache upon reload. Some documentation of all this stuff would be really helpful, if anyone who understands it for sure wants to write some. Jeff Cohen wrote: > > Actually, that's only true during a single action (request-response > cycle). Once your action is over, the cache is cleared. > > You should always be getting new data. If you need to get fresh data > within an action, > you can reload the model. > > @order.reload > > or > > @order.products(true) # reloads associated products collection -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Rails 2 caching?
There's a part of my code that really needs to get the latest value from the database. But AR in Rails 2 seems to have some kind of caching, so if I execute a Model.find statement with the exact same arguments, it won't go to the database, it'll just return the same value it got last time? At least that's the only way I can explain the weird behavior I am seeing. This seems like rather an evil thing to turn on by default, but at any rate, if I'm right about what's going on... how do I disable this for an individual Model.find command, where I really need to get fresh data? Jonathan -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] serialize with Marshal, YAML, or what?
If I want to serialize/unserialize arbitrary objects (not just ARs) in a Rails app, what's the best way to do it? Using 'Marshal' seems to be ruby standard. But then there's YAML. And then I feel like maybe Rails adds yet another way to do it, but I can't remember what it is and might be imagining that. I don't understand the plusses/minuses of each option. I just want to be able to serialize/unserialize arbitrary objects, what's my best bet? Jonathan -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: migration error, mysql, change column limit
Nevermind, as usual my own stupid error. Jonathan Rochkind wrote: > Hmm, one of my migrations have stopped working on #down. It still works > on #up. (It's also possible that I never tested it for #down before, and > it never worked, heh.) -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] migration error, mysql, change column limit
Hmm, one of my migrations have stopped working on #down. It still works on #up. (It's also possible that I never tested it for #down before, and it never worked, heh.) I can't figure out why not. Pretty simple. class WidenRequestParams < ActiveRecord::Migration def self.up change_column :requests, :params, :string, :limit => 2048 end def self.down change_column :requests, :params, :string, :limit => 1024 end end Up works fine. Down tells me: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit1024 DEFAULT NULL' at line 1: ALTER TABLE `requests` CHANGE `params` `params` limit1024 DEFAULT NULL Why is it messing up the SQL on 'down', but not 'up'? Very weird. Anyone have any ideas? -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: does anyone know whether ActiveRecord has supported connection pool?
It has to do with multiple connections to one database. It has, however, always been possible to have some models living in one database, and others living in others, if that's what you want. Relationships accross databases don't always work perfectly, if you're trying to do fancy things. (Like, pre-loading a relationship accross databases). For using multiple databases in your app, see: http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases Incidentally, even pre Rails 2.2, I have had success using multiple connections to a single db in different threads, using the mysql gem adapter. Now I wonder if the mysql gem adapter is actually non-blocking though, or if my different threads were still blocking on db access. Jonathan boblu wrote: > Can anybody tell me about this? > Does this "connection pool" have something to do with multiple > database connection? > Or it is only for concurrent access with one database? -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] generator with prompted user input?
Is there any good way to have a generator prompt for user input (with a default) as part of it's processing? Sort of like when there's a conflict, and you haven't set an argument other than 'ask', it asks you whether to overwrite the file. Can I provide my own user input prompts for my own purposes? Thanks for any help, Jonathan -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: customize logger messages in Rails2?
Argh, this still isn't quite there yet. Now I can't start my app with script/console, which is convenient sometimes. Because in script/console, somehow ActiveSupport hasn't yet been loaded when it loads the environment. So I had to add a "require 'active_support'" to my environment, and now console is happy. I hope that won't mess up anything else in the Rails load order. I had no idea I'd have to get so much into the guts of Rails just to set a custom log format. Jonathan Rochkind wrote: > Okay, I finally figured out how to get this to work. Leave this here for > future list archive searchers, since I had to put together a bunch of > pieces. > > My custom logger, based on this patch: > http://rails.lighthouseapp.com/projects/8994/tickets/1307-bufferedlogger-should-support-message-formatting > > is in my lib/umlaut_logger.rb. So now that custom logger can take a > formatter, like standard ruby Logger can. > > For some reason, inside the environmental config block, auto-loading > from constants doesn't seem to work yet, I needed to require_dependency > it automatically. Then, I really wanted to take the existing log and > severity level fields from RAILS_DEFAULT_LOGGER, but > RAILS_DEFAULT_LOGGER isn't set yet here. But if I wait until it IS set, > then it's too late for re-setting it to easily have an effect. So I had > to reconstruct what it did from source, and other people's suggetsions > in the listserv archives. > > So, in the config block: > > require_dependency 'umlaut_logger' > severity_level = > ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) > log_file = File.join(RAILS_ROOT, "log", "#{RAILS_ENV}.log") > > our_logger = UmlautLogger.new(log_file, severity_level) > # eg, my real one is more complicated: > our_logger.formatter = lambda {|severity_label, message| > "#{severity_label}: #{message}"} > > config.logger = our_logger > > > That was kind of a lot of work to get custom formatting. Phew. -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: customize logger messages in Rails2?
Okay, I finally figured out how to get this to work. Leave this here for future list archive searchers, since I had to put together a bunch of pieces. My custom logger, based on this patch: http://rails.lighthouseapp.com/projects/8994/tickets/1307-bufferedlogger-should-support-message-formatting is in my lib/umlaut_logger.rb. So now that custom logger can take a formatter, like standard ruby Logger can. For some reason, inside the environmental config block, auto-loading from constants doesn't seem to work yet, I needed to require_dependency it automatically. Then, I really wanted to take the existing log and severity level fields from RAILS_DEFAULT_LOGGER, but RAILS_DEFAULT_LOGGER isn't set yet here. But if I wait until it IS set, then it's too late for re-setting it to easily have an effect. So I had to reconstruct what it did from source, and other people's suggetsions in the listserv archives. So, in the config block: require_dependency 'umlaut_logger' severity_level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase) log_file = File.join(RAILS_ROOT, "log", "#{RAILS_ENV}.log") our_logger = UmlautLogger.new(log_file, severity_level) # eg, my real one is more complicated: our_logger.formatter = lambda {|severity_label, message| "#{severity_label}: #{message}"} config.logger = our_logger That was kind of a lot of work to get custom formatting. Phew. -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: customize logger messages in Rails2?
Yeah, thanks. I found this patch, which adds formatter functionality to BufferedLogger: http://rails.lighthouseapp.com/projects/8994/tickets/1307-bufferedlogger-should-support-message-formatting Using that as a guide, I have created a sub-class of BufferedLogger that does what I want, until/unless that makes it into a future Rails release. But now I'm stuck figuring out how to tell Rails to use my new sub-class (or an instantiation of it) of a BufferedLogger. Nothing I try to do seems to work. Setting RAILS_DEFAULT_LOGGER myself to my instantiated logger in environment.rb, no. Setting config.logger to my instantiated logger in environment.rb, no. Anyone figured out how to actually tell Rails2 to use a new logger object? (Odd that it's taken so long to get logging right in Rails.) Jonathan Frederick Cheung wrote: > On 11 Nov 2008, at 18:47, Jonathan Rochkind wrote: > >> been improved in Rails2, is there a cleaner way to do this now? >> >> In Rails1, the only good way I found to customize the logger output >> was >> to myself monkey-patch Logger at the end of environment.rb, over- >> riding >> format_message: >> > Well if you look at the source to BufferedLogger in rails 2, the add > method (which is what the rest of rails appears to be calling) just > appends the message to the buffer. (or in other words looks like you > should be overriding add on ActiveSupport::BufferedLogger or subclass > that and set config.logger to an instance of your subclass) > > Fred -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] custom format with BufferedLogger?
So Rails2 provides a new BufferedLogger class that is used for logging. The old monkey-patched Logger class is deprecated. It's nice that the new BufferedLogger doesn't do that weird monkey patching thing, making it easier to sub-class for custom behavior and set your sub-class as the logger, etc. But oddly, BufferedLogger is not a sub-class of the Ruby logger. It's its own thing. Which seems to provide no good way to set a custom format for output log messages. Anyone figured out a good way to use BufferedLogger (or a subclass), but set your own format for output, like you can with the default ruby Logger class? I wonder why BufferedLogger wasn't made a sub-class of Logger. Jonathan -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: post-initializer hook?
Awesome, thank you, I'll use 2.1 then, and count on the after_initialize hook really actually being after the initializers. Thanks for all your help, Fred. Jonathan Frederick Cheung wrote: > On 11 Nov 2008, at 18:31, Jonathan Rochkind wrote: > >> 116 load_application_initializers >> >> Although I guess I'm looking at 2.0RC1 there. Not familiar enough with >> navigating svn to find the latest release, is there reason to believe >> this has changed? >> > That was changed in 2.1 (which is what I looked at before i wrote my > previous reply) >> I guess I can monkey-patch Rails::process, with the aliasing- >> switcharoo >> trick, to first call the original Rails::process, and then call my own >> really_really_after_initializers method? >> > sounds reasonable if you have to. > > Fred -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] customize logger messages in Rails2?
In Rails2, what's the best way to customize the format of logger output in Rails? In Rails1, due to Rails weird monkey-patching of Logger, you couldn't just subclass Logger and then set it as the logger to be used. Has this been improved in Rails2, is there a cleaner way to do this now? In Rails1, the only good way I found to customize the logger output was to myself monkey-patch Logger at the end of environment.rb, over-riding format_message: class Logger def format_message(severity, timestamp, progname, msg) # stuff to output messages just the way I want. end end However, oddly, in Rails2 this seems to have stopped having any effect at all. The logger output is still uncustomized, Rails default. Any advice? Thanks in advance to Frederick if he pays attention to this, because so far he's the only one who both understands what I'm talking about and pays attention to me :) I already owe you many beverages of your choice, Frederick. -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: post-initializer hook?
Thanks Frederick. But, documentation and googling that led me to source suggests that the after_initialize hook is called _before_ config/initializers are. http://dev.rubyonrails.org/browser/tags/rel_2-0-0_RC1/railties/lib/initializer.rb#L340 114 after_initialize 115 116 load_application_initializers Although I guess I'm looking at 2.0RC1 there. Not familiar enough with navigating svn to find the latest release, is there reason to believe this has changed? I guess I can monkey-patch Rails::process, with the aliasing-switcharoo trick, to first call the original Rails::process, and then call my own really_really_after_initializers method? Jonathan Frederick Cheung wrote: > On 11 Nov 2008, at 18:07, Jonathan Rochkind wrote: > >> >> Is there any callback/hook for me to add some code to be called after >> all initializers (config/initializers/*) are called, in Rails 2? >> > config.after_initialize do > ... > end > > Fred -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] post-initializer hook?
Is there any callback/hook for me to add some code to be called after all initializers (config/initializers/*) are called, in Rails 2? Or should I count on initializers being run in sort order and add one called _after_all_initializers.rb or something? Any advice? Jonathan -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Rails 2.1.2 bug in include on has_many?
The odd thing is that I get away with over-riding [] and []= until I try defining an association with a pre-fetch :include that involves the model with the over-ridden [] and []=. And googling around, I can see several people suggesting over-ridding [] and []= on an AR model to accomplish various clever things. So maybe it is a bug? Regardless, I think I'll try to refactor to do not do that to avoid the risk of getting in the way of AR. It seems to be rather easier than one would like to get in the way of AR. In particular, the too-clever thing I was doing was having an AR that could take arbitrary keys and either store them in an attribute, if it exists, or in a serialized hash, if otherwise. An excerpt of the relevant stuff: def MyThing < ActiveRecord::Base serializes :my_data def [](key) if ( has_attribute?(key) ) self.send(key) else my_data[key] end end def []=(key, value) if ( has_attribute?(key) ) self.send(key.to_s+'=', value) else my_data[key] = value end end All well and good--until I try to define an association with :include => MyThing . Jonathan Rochkind wrote: > Yeah, you're right, sorry, thanks so much for your help. Probably for > the best that i changed the model name from Request anyway, might as > well commit that to my svn since it's advertised as a Rails reserved > word. > > I just posted this to the forum with a different subject, since it ended > up having nothing to do with this, but. But I was forced to really get > down and dirty with my testing, and it turns out it's because I had > over-ridden [] and []= on one of the models involved. I got away with > that in Rails 1 (perhaps AR didn't used to use these methods?), but not > in Rails 2. Okay, more refactoring, this one's even more of a pain then > the last one. Oh well, I guess I was being too clever before. > > Jonathan > > Frederick Cheung wrote: >> On 10 Nov 2008, at 21:04, Jonathan Rochkind wrote: >> >>> >>> Hmm, just changing the model name from Request to AppRequest doesn't >>> seem to have done it. >>> >>> I tried to leave the (many) associations pointing to AppRequest (nee >>> Request) the same, but specify a :class_name and :foreign_key. >>> >>> It sounds like maybe "request" as the name of an assocation, even when >>> not the name of the model, is a no-no too? >> >> I'm not convinced that has anything to do with this at all. If you >> could post your teeny tiny example I might be able to work out what is >> going in (given that I wrote the code behind include in 2.1.2) >> >> Fred -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Rails 2.1.2 bug in include on has_many?
Yeah, you're right, sorry, thanks so much for your help. Probably for the best that i changed the model name from Request anyway, might as well commit that to my svn since it's advertised as a Rails reserved word. I just posted this to the forum with a different subject, since it ended up having nothing to do with this, but. But I was forced to really get down and dirty with my testing, and it turns out it's because I had over-ridden [] and []= on one of the models involved. I got away with that in Rails 1 (perhaps AR didn't used to use these methods?), but not in Rails 2. Okay, more refactoring, this one's even more of a pain then the last one. Oh well, I guess I was being too clever before. Jonathan Frederick Cheung wrote: > On 10 Nov 2008, at 21:04, Jonathan Rochkind wrote: > >> >> Hmm, just changing the model name from Request to AppRequest doesn't >> seem to have done it. >> >> I tried to leave the (many) associations pointing to AppRequest (nee >> Request) the same, but specify a :class_name and :foreign_key. >> >> It sounds like maybe "request" as the name of an assocation, even when >> not the name of the model, is a no-no too? > > I'm not convinced that has anything to do with this at all. If you > could post your teeny tiny example I might be able to work out what is > going in (given that I wrote the code behind include in 2.1.2) > > Fred -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] override [] and []= on an ActiveRecord
Okay, I finally figured out what was going on with my mysterious migrate-to-Rails2 problem. In Rails 1.x, I got away with over-riding [] and []= on an ActiveRecord::Base model class. This made for some very convenient coding, which is now littered all over my application. In Rails2, you apparently can't do this. Should I assume this is right, rather than a bug? Should it be documented anywhere? Still trying to think through the best least painful way to refactor my code. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Rails 2.1.2 bug in include on has_many?
Hmm, just changing the model name from Request to AppRequest doesn't seem to have done it. I tried to leave the (many) associations pointing to AppRequest (nee Request) the same, but specify a :class_name and :foreign_key. It sounds like maybe "request" as the name of an assocation, even when not the name of the model, is a no-no too? Man, that lengthy lengthy list of reserved words, which wasn't really official documentation anyway and seems to be have been discovered only by experimentation... is leading to one of those times I'm less happy with ruby/rails. I've got a lot of refactoring to do. Changing the many association names to this model every time they are used is not going to be fun. Jonathan Jonathan Rochkind wrote: > Thanks a lot Chris. Sadly, I've got my work cut out for me, as changing > the name of the model in this fairly mature application is going to be > some work. But at least it all makes some sense now. > > Is it possible to change the model name without changing the name of the > _associations_ that point to it in other models? Or, I guess, to alias > the association name 'request' to an 'actual' association named > service_request or whatever. To give me less code that has to be > changed? Any advice as to the lowest impact way to change a model name > in a mature application with lots of code that refers to that model, and > to associations in other models that point to that model? > > Odd that I got away with it in Rails 1.x, but oh well, I guess it was > really incorrect all along. > > Jonathan > > Chris Bartlett wrote: >> Jonathan is probably right. 'Request' is a reserved word in Rails - >> see http://wiki.rubyonrails.org/rails/pages/ReservedWords >> >> Try changing the model name to ServiceRequest or similar. >> >> On Nov 7, 6:43�am, Jonathan Rochkind <[EMAIL PROTECTED] -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Rails 2.1.2 bug in include on has_many?
Thanks a lot Chris. Sadly, I've got my work cut out for me, as changing the name of the model in this fairly mature application is going to be some work. But at least it all makes some sense now. Is it possible to change the model name without changing the name of the _associations_ that point to it in other models? Or, I guess, to alias the association name 'request' to an 'actual' association named service_request or whatever. To give me less code that has to be changed? Any advice as to the lowest impact way to change a model name in a mature application with lots of code that refers to that model, and to associations in other models that point to that model? Odd that I got away with it in Rails 1.x, but oh well, I guess it was really incorrect all along. Jonathan Chris Bartlett wrote: > Jonathan is probably right. 'Request' is a reserved word in Rails - > see http://wiki.rubyonrails.org/rails/pages/ReservedWords > > Try changing the model name to ServiceRequest or similar. > > On Nov 7, 6:43�am, Jonathan Rochkind <[EMAIL PROTECTED] -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Rails 2.1.2 bug in include on has_many?
Frederick Cheung wrote: > On 6 Nov 2008, at 16:39, Jonathan Rochkind wrote: > >> [...] >> > >> There's no reason this wouldn't be supported in Rails 2.1.2, is there? >> > > It should work. :include was rewritten for rails 2.1 though. > service_type has a belongs_to :service_response ? > > Fred It sure does. This is annoying me highly. I've pared down my code to a simple reproducible test case. And it's still exhibiting. i can't figure out what I'm doing to trigger the bug, if everyone else is using :has_many, :include without problems. Very frustrating. -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Rails 2.1.2 bug in include on has_many?
Hmm, is it possible that the fact that the model is named "Request" is somehow triggering the bug? That's the only thing I can figure out. Jonathan Jonathan Rochkind wrote: > Frederick Cheung wrote: >> On 6 Nov 2008, at 16:39, Jonathan Rochkind wrote: >> >>> [...] >>> >> >>> There's no reason this wouldn't be supported in Rails 2.1.2, is there? >>> >> >> It should work. :include was rewritten for rails 2.1 though. >> service_type has a belongs_to :service_response ? >> >> Fred > > It sure does. > > This is annoying me highly. I've pared down my code to a simple > reproducible test case. And it's still exhibiting. i can't figure out > what I'm doing to trigger the bug, if everyone else is using :has_many, > :include without problems. Very frustrating. -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Rails 2.1.2 bug in include on has_many?
In my continued efforts to port my rails 1.x app to Rails 2.1.2, I keep running into what appear to be ActiveRecord bugs. I am using an :include on a :has_many definition: class Request < ActiveRecord::Base has_many :service_types, :order=>'service_types.id ASC', :include=>:service_response [...] There's no reason this wouldn't be supported in Rails 2.1.2, is there? Worked fine in Rails 1.2.6. In Rails 2.1.2, I fetch in a Request objects, and then I try to call some_request.service_types, and I get an exception. Anyone run into this? Any ideas? That :include is really useful to me for efficiency. You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:74:in `set_association_single_records' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:67:in `each' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:67:in `set_association_single_records' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:242:in `preload_belongs_to_association' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:219:in `each' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:219:in `preload_belongs_to_association' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:40:in `send' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:40:in `preload_one_association' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:38:in `each' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:38:in `preload_one_association' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:17:in `preload_associations' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:16:in `preload_associations' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:16:in `each' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/association_preload.rb:16:in `preload_associations' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:1347:in `find_every' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/base.rb:540:in `find' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/associations/association_collection.rb:47:in `find' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/associations/association_collection.rb:308:in `find_target' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/associations/association_collection.rb:262:in `load_target' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/associations/association_proxy.rb:169:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/associations/association_collection.rb:279:in `method_missing' app/controllers/test_controller.rb:9:in `index' -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Rails 2.1.2, complex find involving complex include, bug?
Hmm, again answering my own question as soon as I ask it (writing this stuff out is sure helpful for clarifying your thoughts), poking around in the AR documentation leads me to another workaround. Specify the classname explicitly in the model relationships, even though it really shouldn't be needed. module SfxDb class AzTitle < SfxDbBase belongs_to :sfx_object, :class_name => "SfxDb::SfxObject" [...] end That's a reasonable workaround, although it really shouldn't be neccesary. Anyone want to help me figure out the right way to report this as a bug? Jonathan Jonathan Rochkind wrote: > So I'm upgrading my app from Rails 1.2.6 to Rails 2.1.2. > > I have a complex find statement that worked in 1.2.6 and isn't working > in 2.1.2. I think maybe this is a bug, although maybe there's something > else I could be doing to work-around it? > > My find statement involves: > * Models in a module for namespace purposes > * a join clause with raw SQL > * an includes clause with multiple levels (the hash syntax) > > This worked in 1.2.6: > > *** > joins = " inner join AZ_LETTER_GROUP_VER3 as lg on > AZ_TITLE_VER3.AZ_TITLE_VER3_ID = lg.AZ_TITLE_VER3_ID" > > conditions = ['lg.AZ_LETTER_GROUP_VER3_NAME = ?', 'A'] > batch_size = 10 > page = 1 > > > az_titles = SfxDb::AzTitle.find(:all, > :joins => joins, > :conditions => conditions, > :limit => batch_size, > :offset=>batch_size*(page -1), > :order=>'TITLE_SORT', > :include=>[{:sfx_object => [:publishers, :titles] }]) > > > However, in 2.1.2, it raises an error, ActiveRecord can't find the > SfxObject model class anymore--probably because it's in a module > namespace, SfxDb::SfxObject. It says: > > uninitialized constant SfxObject > /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:279:in > `load_missing_constant' > [...] > /usr/lib/ruby/gems/1.8/gems/activesupport-2.1.2/lib/active_support/core_ext/string/inflections.rb:143:in > `constantize' > [...] > /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/associations.rb:1652:in > `remove_duplicate_results!' > [...] > /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active_record/associations.rb:1261:in > `find_with_associations' > > > Now, here's the weird thing. If I remove that _complex_ include > statement, and remove the extra levels, it works fine: > > az_titles = SfxDb::AzTitle.find(:all, > :joins => joins, > :conditions => conditions, > :limit => batch_size, > :offset=>batch_size*(page -1), > :order=>'TITLE_SORT', > :include=>[:sfx_object]) > > > So this smells like a bug to me. I need those extra levels for > efficiency! > > Also, if I remove the models from a module namespace, it works fine. > > So it seems to be a bug in the code for multi-level include and models > in modules. > > Should I report this bug somewhere/somehow? Not sure of Rails bug > reporting standards. > > I guess the workaround is to remove my models from a module namespace. > But that's really unfortunate, it keeps things so much tidier to have > them there, they're really a special purpose subset of my models. Can > anyone think of any other workaround? -- 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---