ruby-on-rails

Error while connecting to a remote solr instance from Sunspot

I am using Sunspot rails(1.1.0). Everything works when I run my Rails application and the Solr server on the same machine. When I run Solr server on a different machine, I get the following error: Errno::ECONNREFUSED: Connection refused - Connection refused from /opt/tibco/jruby-1.4.0RC1/lib/ruby/1.8/net/http.rb:560:in `initialize' from...

Is it possible to work with HTTParty request results as an object

Hi guys, I wonder if it possible to work with HTTParty (http://github.com/jnunemaker/httparty) request results as an object. Currently i use string keys to access to values of result: result["imageurl"] or result["address"]["street"] If i were in JavaScript I could simply use: result.imageurl or result.address.street Regards, Alexe...

Upgrading irb on OS X

Hello, I'm trying to update irb on my OS X 10.5 macbook: $ irb -v irb 0.9.6(09/06/30) I'm currently learning Ruby and was following the "Why's Poignant Guide to Ruby" and on this page: http://mislav.uniqpath.com/poignant-guide/book/expansion-pak-1.html they mention auto-completion in irb requires version 1.8 of irb. I'm not sure ent...

Click on word and get the definition...?

I am looking to have a user click on a word and a tip shows up above the word showing the definition. The definitions will come from a glossary of words we already have. We are using Ruby and Jquery for the site. Any suggestions or a finger pointing in a direction? ...

RMagick warning while running server

I am using gem 1.3.7, rails 2.3.5 and ruby 1.8.7 (2008-08-11 patchlevel 72). While starting server i get below warnings. Loading development environment (Rails 2.3.5) /Users/me/.rvm/gems/ruby-1.8.7-p72@mbm/gems/rmagick-2.13.1/lib/RMagick.rb:44: warning: already initialized constant PercentGeometry /Users/me/.rvm/gems/ruby-1.8.7-p72@mbm...

link_to param scoping in rails?

I have a page which has a couple option links that set GET-based parameters to the page. These links are created with the Rails HtmlHelper: link_to section, {:company_id => params[:company_id], :view => section} Notice how I have to retype out parameters just in case they've been selected before. I want to know if I can achieve this...

It's this a bug in rails? about single table inheritance;

class Parent < ActiveRecord::Base end class Sub < Parent end class SubSub < Sub end >> SubSub.create :name => 'name1' >> SubSub.create :name => 'name2' >> SubSub.create :name => 'name3' Then >> SubSub.all.map{|x| x.name} # => ['name1', 'name2', 'name3'] >> Sub.all.map {|x| x.name} # => [] # I was expected that it ...

Rails gem: What is the best way to keep all versions of database objects and to save changes linked to a user?

I have a collaborative app environment, where I need to store/log information on who changes what in the system. All versions of every object needs will be saved with user information, and no data can ever be deleted. What should I look at besides extending vestal_versions? ...

Automatic generation of CSS from SCSS/SASS with HAML and Rails

Hi, Is there a way to get your SCSS files to automatically generate new CSS each time a file is changed as part of Rails, without having to use sass --watch? Or is this just meant to happen anyway? By this I mean having rails do the watching for you, or maybe if it can recompile all SCSS every page load in development that is fine too....

Ruby-Proper Usage of the Date.step() method

I have been trying to use the step() method on Date object to retrieve the previous 2 dates from the current date as follows: date_d.step(2, step=-2){|d| puts d } where 2 is the limit and step is the number of steps backward or forward. I have done this in accordance with the Documentation given here: Date.step() Thi...

JSON objects with RoR accross multiple tables

What I want to do is make a JSON object which contains the outlet info, as well as the switch name and the switch port corresponding to that outlet. I know how to do it without using JSON, but it will be unpleasant and I will have to repeat the process for each outlet. There must be a better way. i looked at ActiveRecord::Serialisation ...

Rails embedding syntax doubt

Hi ,, I have been working ROR now.. I am very new to ROR.. Could anyone tell me of what is the difference between <%= %> and <%=h %> why we have h here ?? in some cases i have seen t instead of h.. Please clarify me ...

Problem with testing validations using Shoulda .

Here's my test. class AlertSettingTest < ActiveSupport::TestCase context "For ALL Alert Settings" do setup do @alert = AlertSetting.create({ :alert_type_id=>'1',:name => 'xxx'}) end subject { @alert } should_belong_to :alert_type should_validate_presence_of :name end end Here's my model. class AlertSetting < ActiveR...

RoR, RSpec - problem with validation testing

Through rspec (I'm using rspec-1.3.0, rspec-rails-1.3.2 gems) generator (ruby script/generate rspec_model suggestion section_id:integer user_id:integer subject:string content:text state:string type:string) I created model and model spec and run rake db:migrate and rake:test:prepare After that I started to work on my model spec: require...

Rails: how do I validate that something is a boolean?

Does rails have a validator like validates_numericality_of for boolean or do I need to roll my own? ...

How do I use rails 2.3.8 with declarative authorization on heroku?

help rails 3 came out yesterday, we have a fully functional rails 2.3.8 app, but our deployment on heroku doesn't work because declarative_authorization demands rails 2.1 or higher That is a very big problem, how can I solve it, any quick hacks, workarounds? ...

Referential Data Integrity: Necessity, nice-to-have, or old hat?

Frameworks like Rails have encouraged moving a lot of the logic, even stuff like constraints and foreign keys, off the database - in my opinion. for the better, as it's more manageable and easy to change. Even so, some operations are easier faster, or just plain only possible in SQL. The recent explosion in popularity of noSQL databa...

activerecord3 IN statement with array

This must be super basic, but I just can't figure it out. I want to select from a table with lots of tag names all the tags who aren't part of the array 'tagnames'. I tried: Tag.where( "name != ?", tagnames ) gives me "Operand should contain 1 column(s)" Tag.where( "name NOT IN ?", tagnames ) gives me a SQL error I know h...

"You are being redirected" bug in Rails 2.3.8 + mongrel

We've recently upgraded Rails to 2.3.8 (from something so ancient you don't wanna know). Everything was going fine and everything worked just fine in development, then when we put it up on staging we discovered that redirections suddenly stopped working. Instead of being redirected (say during login) we just got a blank page that says ...

RoR retrive jquery session value in rails html.erb

hi i have assigned session value in jquery, as $.session("example","mysession"); and when is retrive it in html.erb page, i am not getting session value.. please, give me solution for this.. how to retrive jquery session value in erb file thanks ...