Anyone using JRuby-Rack with Rails 3? - jetty

Is anyone else out there running Rails 3 and JRuby-Rack, or Jetty and Rails 3? Any trick to it? I'm going insane with some debugging, and at this point I just want to know that it's possible.

These instructions work for me:
http://mathias-biilmann.net/2010/2/jruby-and-rails-3-beta-step-by-step

i am using jetty-rails + rails3 for a couple of projects. jetty-rails need to be fixed , require "activesupport" need to be changed to require "active_support" (for activesupport 3.0.3) and you have also do 'require "active_support/all"' to include hash extensions (otherwise symbolize! & reverse_merge method will raise exceptions.. right now trying to fix some jruby-rack issues.. (Rack::Runtime not loaded)..will update once thats done.

Related

Toggle! Bang Change in Rails 4

Trying to solve a mystery for the purpose of documentation.
We're upgrading from Rails 3.2 to Rails 4.
In the Rails 3.2 code, we have (well, had):
def update_object_special_eligibility
object.toggle!(:can_run_on_special) if object && object.can_run_on_special? && ineligible_for_special?
end
I realize this doesn't give you all the information you need, but here is the error. You should know that can_run_on_special is a bitfield rather than an official attribute, though I don't think it's actually relevant. Just thought I'd let you know why we were getting the error:
1) Error:
ObjectStatusTest#test_should_mark_object_as_not_eligible_to_run_on_special_for_specific_unschedule_reasons:
ActiveModel::MissingAttributeError: can't write unknown attribute `can_run_on_special'
config/initializers/acts_as_audited.rb:280:in `write_attribute_with_audit'
app/models/object_status.rb:437:in `update_deal_amazon_eligibility'
test/unit/object_status_test.rb:481:in `block in <class:ObjectStatusTest>'
test/fast_test_helper.rb:99:in `call'
test/fast_test_helper.rb:99:in `block in <class:TestCase>'
The code we changed it to that works on Rails 4:
def update_object_special_eligibility
if object && object.can_run_on_special? && ineligible_for_special?
object.update_attributes! :can_run_on_special => false
end
My suspicion is that because toggle! operates like update_attribute in terms of bypassing validations that it's just returning false for saving the attribute, and therefore, toggle! just doesn't work anymore because the updating of the attribute and the saving isn't working. But I am not sure that's the case. I'm hoping someone out here might have some idea about why this ActiveRecord::Persistence method (toggle!) might be operating differently in Rails 4. Or, is it the updating of the "attribute" and saving that is likely operating differently?
Thanks so much!
Looks like acts_as_audited is getting in on the act, and isn't bitfield/toggle savvy, would be my guess. Too many cooks hacking in their wares here. (bitfield and acts_as_audited).

Mongoid 4 finding embedded documents by ID

I have a project that is my first serious dive into Mongoid.
I saw a tip to use the following command:
Parent.where('childrens._id' => Moped::BSON::ObjectId(params[:id])).first
But this doesn't work. Error message was:
NameError: uninitialized constant Moped::BSON
I found that BSON is no longer included, so I added it to my Gemfile, as well as Moped. Then, I did another fix I found (placing Moped::BSON=BSON in application.rb).
This still didn't work, but the error changed to:
NoMethodError: undefined method `ObjectId' for BSON:Module
So I am assuming that this method got deprecated or something. Does anyone have any other tips?
Just to be clear, I am finding myself in the situation where I want to sort embedded documents using jquery-sortable. This requires me to update them in the database, but the serialize from that doesn't include the parent document in the hash. So I figured I'd try to get it on the back end using an ID from the embedded document. That is why I need it.
Thanks again for any help you can provide.
Try simply:
Parent.where('childrens._id' => params[:id]).first
I have solved the question though this won't be of much help to people in the future. The requirements have changed and now I am using human-readable strings as IDs to assist in friendly URLs and some other stuff.
Therefore, I don't have any issues with ObjectIds. Cortex's solution should (from what I have read) work for dealing with ObjectIds but I cannot verify it now.

Using multiple jQuery versions problem

I am building control that uses last version of jstree. Problem is that whole system is build using jQuery 1.3.2, but i need to use jQuery 1.4.2 for jstree, also to prevent errors need "$" still pointing to jQuery 1.3.2 to make system works normally. I tried to solve problem like this
var jq142 = jQuery.noConflict(true);
And it works, but when i added other control to form like "datepicker" that initialized via $("#id").datepicker it throws error $("#id").datepicker is not a function
When i inspect DOM variables through firebug all is ok - $ is pointing to 1.3.2 and datepicker function is registered.
What it can be?
Thanks
in case anyone came to this by looking for unanswered questions, the answer was to simply upgrade to 1.4.*
btw: jQuery 1.7 has just been released... time to upgrade again ;-)

Unit test with Authlogic on Rails 3

I would like to write some unit test with a logged user using Authlogic. To start right, I used some code hosted in http://github.com/binarylogic/authlogic_example. But I get an error after rake test, because of "test_helper.rb" and the following class:
class ActionController::TestCase
setup :activate_authlogic
end
Here is my error:
NameError: undefined local variable or
method `activate_authlogic' for
I think this Authlogic example is mapped over Rails 2; maybe it's a little bit different on Rails 3. Is there an other example where I can take example about unit test?
Many thanks.
Do you require 'authlogic/test_case' and include Authlogic::TestCase?
I had a similar issue (using rspec, though) and read through the code at http://github.com/trevmex/authlogic_rails3_example
As of Rails 3.1 and Authlogic 3.0.3, the only thing I've had to add to activate authlogic was
features/support/env.rb
Before do
activate_authlogic
end
I don't realize where to put include Authlogic::TestCase, so I put this after the requires in spec_helper.rb and it worked. There is a better place for it?

apache solr auto suggestions

I use solr+django-haystack
I set settings.HAYSTACK_INCLUDE_SPELLING = True
and rebuild index
I'm trying to get any suggestion using:
SearchQuerySet().auto_query('tryng ani word
her').spelling_suggestion()
But I always get None
What should I do to get at least one working suggestion ? may be I
need add some configuration into solr config or have some specific
data indexed ?
Depending on what version of solr you're using you could use EdgeNGrams or the TermsComponent (if your using 1.4). Check out these links, they should get you started in the right direction. I haven't used haystack, so I don't know if there's an easy way to use leverage these solutions in that framework.
EdgeNGrams:
www.lucidimagination.com/blog/2009/09/08/auto-suggest-from-popular-queries-using-edgengrams/
TermsComponent:
wiki.apache.org/solr/TermsComponent
www.lucidimagination.com/search/document/CDRG_ch07_7.13.3
you need to add spelling support to your default request handler in solr conf
see this please
http://wiki.apache.org/solr/SpellCheckComponent