Auto-generated Dropdown with dependency in Surveyor (Rails gem) - ruby-on-rails

I am trying to setup a question in surveyor (http://github.com/NUBIC/surveyor/) that has a dropdown box with values 1 to 50. The next question should only be visible if the the user chooses 1 in the first question. Here is my code to do this:
survey "Test survey dependency", :default_mandatory => true do
section "questions" do
q_1 "Click on 1 to see the next question", :pick => :one, :display_type => :dropdown
((1..49).to_a + ["50 or more"]).each{|num| a num.to_s, reference_identifier: num.to_s}
q "Hello?"
a "Hello"
dependency :rule => "A"
condition_A :q_1, "==", {:answer_reference => "1"}
end
end
Now, this should compare :q_1 with :a_0. However this is the error I get:
rake surveyor FILE=surveys/survey.rb
rake aborted!
Bad references: q_1, a_0
/home/ari/.rvm/gems/ruby-1.9.3-p392/gems/surveyor-1.3.0/lib/surveyor/parser.rb:59:in `instance_eval'
/home/ari/.rvm/gems/ruby-1.9.3-p392/gems/surveyor-1.3.0/lib/surveyor/parser.rb:120:in `report_lost_and_duplicate_references'
/home/ari/.rvm/gems/ruby-1.9.3-p392/gems/surveyor-1.3.0/lib/surveyor/parser.rb:84:in `method_missing'
(eval):1:in `parse'
If I change condition_A to condition_A :q_1, "==", {:string_value => "1"}, it gets parsed successfully but the next question is still never shown.
Everything in the example, kitchen_sink_survey.rb works fine.
So it looks like setting :reference_identifier manually doesn't do anything. Is this a bug or by design? And can I do anything about it apart from test for the actual value?

This was actually a bug in surveyor, but it has now been fixed on github: https://github.com/NUBIC/surveyor/commit/a9b68f668da936fbe16fc89448e53c463b867dc0

Related

How do I tell PG use the database.yml file?

Here is a simple database connection, and query thats working for me;
postgre_conn = PG::Connection.open(:host => 'dbsvr', :user => 'csdashboard', :password => 'csdashboard', :dbname => 'csdashboard')
#filtered_snort_detail_query = postgre_conn.exec("SELECT * from event where timestamp >= (now() - '1 day'::INTERVAL);")
How can I tell pg to use the database.yml file for connection information?
#
#
Closed issue
#
#
I'm sorry to waist everyones time, I think I was doing this all wrong. Since this is a database function, I think it needs to be defined by a model first. Very sorry for that...

What is wrong with this Sunspot Solr setup?

I am using sunspot to search my local db. After adding the gems, running the generate command, and booting up the solr server I do the following:
class Style < ActiveRecord::Base
attr_accessible :full_name, :brand_name
searchable do
text :full_name
text :brand_name
end
end
Added the above to my Style model and re-indexed (I had already indexed prior to creating this post, which is why I re-indexed to put it here)
funkdified#vizio ~/rails_projects/goodsounds.org $ rake sunspot:solr:reindex
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
*Note: the reindex task will remove your current indexes and start from scratch.
If you have a large dataset, reindexing can take a very long time, possibly weeks.
This is not encouraged if you have anywhere near or over 1 million rows.
Are you sure you want to drop your indexes and completely reindex? (y/n)
y
[#######################################] [14/14] [100.00%] [00:00] [00:00] [53.19/s]
Then I try a search and get nothing
1.9.3p392 :003 > Style.search { fulltext 'Monkey' }.results
SOLR Request (10.4ms) [ path=#<RSolr::Client:0x0000000685ab28> parameters={data: fq=type%3AStyle&q=Monkey&fl=%2A+score&qf=full_name_text+brand_name_text&defType=dismax&start=0&rows=30, method: post, params: {:wt=>:ruby}, query: wt=ruby, headers: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, path: select, uri: http://localhost:8982/solr/select?wt=ruby, open_timeout: , read_timeout: , retry_503: , retry_after_limit: } ]
=> []
But, wait shouldn't it have worked and picked this up?
Style.first
Style Load (1.3ms) SELECT "styles".* FROM "styles" LIMIT 1
=> #<Style id: 54, brand_name: "Monkey", full_name "Monkey Chicken", created_at: "2013-02-01 23:25:58", updated_at: "2013-02-16 03:02:16">
Here is one more clue. I am seeing "unknown field" for brand_name (setup in Style.rb)
If you change the schema (the "searchable" block) you have to either reindex all models:
rake sunspot:solr:reindex
or reindex that specific model with a given batch size (here 500):
rake sunspot:solr:reindex[500,Style]
as per the Sunspot doco on Github (search "Reindexing Objects").
FYI, to use Style.reindex for non-schema changes, you will have to call Sunspot.commit to save changes.

PostgreSQL and Heroku, find and group

I'm trying to get an app to run on Heroku properly. (Heroku uses the postgreSQL database, yeh?)
In development, I'm using sqlite, and this is my code in a controller =>
#productsort = Products.find(:all,
:select => 'count(*) count, color',
:group => 'color',
:order => 'count DESC',
:conditions => 'size = "Small"')
As you can see, I'm trying to group products by their colors, and order them by greatest amount to least.
Also, the products must be "Small". (the conditions)
In SQL, it works fine.
But not in PostgreSQL (heroku).
This is from running "heroku log"
2011-06-20T18:20:33+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR: column "Small" does not exist
2011-06-20T18:20:33+00:00 app[web.1]: LINE 1: ...ducts".* FROM "products" WHERE (size = "Smal...
Hm... I've searched around and I couldn't find anything similar to what I have.
All help would be appreicated. Thank you
You need to be using single quotes around your strings in the conditions (double quotes may work with sqlite, but they definitely don't with PostgreSQL).
So replace your conditions with this:
:conditions => "size = 'Small'"
It will still work in SQLite too.

is there an ordinal to cardinal function in ruby or rails?

I'm trying to find a better way in expressing my cucumbers so I am looking for an ordinal to cardinal function that converts this:
When I fill up the first passenger field
Then I should see the passenger list update with the first passenger details
When I follow "Add Another Passenger"
Then I should see a second passenger field
When I fill up the second passenger field
Then I should see the passenger list update with the second passenger details
into something more dynamic(instead of creating separate steps for each line)
here's a sample of my web steps
When /^I fill up the first passenger field$/ do
fill_in("booking_passengers_attributes_0_first_name", :with => "Blah")
fill_in("booking_passengers_attributes_0_last_name", :with => "blah")
select("5' to 6'", :from => "booking_passengers_attributes_0_height")
select("100 to 150lbs", :from => "booking_passengers_attributes_0_weight")
end
When /^I fill up the second passenger field$/ do
fill_in("booking_passengers_attributes_1_first_name", :with => "Wee")
fill_in("booking_passengers_attributes_1_last_name", :with => "Sir")
select("5' to 6'", :from => "booking_passengers_attributes_1_height")
select("150 to 200lbs", :from => "booking_passengers_attributes_1_weight")
end
See that 0 and 1? I wish to convert "first" to a cardinal number so i can just substitute. You can also just suggest a better way to declare the cukes :)
UPDATED ANSWER
I am in the middle of refactoring but basically I used 1st instead of first and used to_i on that.
When /^I fill up the "([^"]*)" passenger field$/ do |id|
input_id = id.to_i - 1
fill_in("booking_passengers_attributes_#{input_id}_first_name", :with => id)
fill_in("booking_passengers_attributes_#{input_id}_last_name", :with => "Passenger")
select("5' to 6'", :from => "booking_passengers_attributes_#{input_id}_height")
select("100 to 150lbs", :from => "booking_passengers_attributes_#{input_id}_weight")
end
i dont really completely understand,exactly what you want to do, but you can do something like this with active support:
1.ordinalize # => "1st"
2.ordinalize # => "2nd"
1002.ordinalize # => "1002nd"
and there is a action view helper number_in_words to get "first" , "second" etc
i don't know much about cukes sorry,
Use the short-form, easily-parsable ordinal:
When /^I fill up the (\d+)(?:st|nd|rd|th) passenger field$/ do |n|
# etc...
end
This function is built into Chronic:
irb(main):001:0> require 'chronic'
=> true
irb(main):002:0> Chronic::Numerizer.numerize("eighty-fifth").to_i
=> 85

ArgumentError on application requests

I've written a basic Rails 3 application that shows a form and an upload form on specific URLs. It was all working fine yesterday, but now I'm running into several problems that require fixing. I'll try to describe each problem as best as I can. The reason i'm combining them, is because I feel they're all related and preventing me from finishing my task.
1. Cannot run the application in development mode
For some unknown reason, I cannot get the application to run in development mode. Currently i've overwritten the production.rb file from the environment with the settings from the development environment to get actuall stacktraces.
I've added the RailsEnv production setting to my VirtualHost setting in apache2, but it seems to make no difference. Nor does settings ENV variable to production.
2. ArgumentError on all calls
Whatever call I seem to make, results in this error message. The logfile tells me the following:
Started GET "/" for 192.168.33.82 at
Thu Apr 07 00:54:48 -0700 2011
ArgumentError (wrong number of
arguments (1 for 0)):
Rendered
/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.6/lib/action_dispatch/middleware/templates/rescues/_trace.erb
(1.0ms) Rendered
/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb
(4.1ms) Rendered
/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb
within rescues/layout (8.4ms)
This means nothing to me really. I have no clue what's going wrong. I currently have only one controller which looks like this:
class SearchEngineController < ApplicationController
def upload
end
def search
#rows = nil
end
# This function will receive the query string from the search form and perform a search on the
# F.I.S.E index to find any matching results
def query
index = Ferret::Index::Index.new :path => "/public/F.I.S.E", :default_field => 'content'
#rows = Array.New
index.search_each "content|title:#{params[:query]}" do |id,score, title|
#rows << {:id => id, :score => score, :title => title}
end
render :search
end
# This function will receive the file uploaded by the user and process it into the
# F.I.S.E for searching on keywords and synonims
def process
index = Ferret::Index::Index.new :path => "public/F.I.S.E", :default_field => 'content'
file = File.open params[:file], "r"
xml = REXML::Document.new file
filename = params[:file]
title = xml.root.elements['//body/title/text()']
content = xml.root.elements['normalize-space(//body)']
index << { :filename => filename, :title => title, :content => content}
file.close
FileUtils.rm file
end
end
The routing of my application has the following setup: Again this is all pretty basic and probably can be done better.
Roularta::Application.routes.draw do
# define all the url paths we support
match '/upload' => 'search_engine#upload', :via => :get
match '/process' => 'search_engine#process', :via => :post
# redirect the root of the application to the search page
root :to => 'search_engine#search'
# redirect all incoming requests to the query view of the search engine
match '/:controller(/:action(/:id))' => 'search_engine#search'
end
If anyone can spot what's wrong and why this application is failing, please let me know. If needed I can edit this awnser and include additional files that might be required to solve this problem.
EDIT
i've managed to get further by renaming one of the functions on the controller. I renamed search into create and now I'm getting back HAML errors. Perhaps I used a keyword...?
woot, finally found the solutions....
Seems I used keywords to define my actions, and Rails didn't like this. This solved issue 2.
Issue 1 got solved by adding Rails.env= 'development' to the environment.rb file

Resources