Extracting Visual Event 2 output into script

In the Visual Event description, it says that it extracts “which elements have events attached to them”. I can confirm this by running the bookmarklet and seeing all the colour highlights. I would like to extract this information without the fancy presentation so that I can play around with it into a script (Ruby/Python/Perl). In […]

Sign Up Form Error: undefined method `model_name' for NilClass:Class

So this is my first attempt kind of just going without tutorial direction on building a site on RoR. Running into some trouble setting up my email signup form. I think there is an issue with how my model is setup or connected but not too sure. Getting “undefined method `model_name’ for NilClass:Class” as the […]

Node.js ruby subprocess hangs

Based on the example here, I’m trying to spawn a ruby process (v1.8.7) from Node.js (v0.4.8). A process and an empty log file are created, but nothing happens until I kill it. If I leave out the STDIN.each_line bit, the code runs fine. I suspect something stdin doesn’t finish so ruby is still waiting for […]

Setting an instance variable in a class scope method

I want to create an instance variable when a certain method is called and also set it to a default value. The instance should then only be able to get the variable but not set it. Here’s a piece of code to showcase my problem: class Foo def self.bar(var) attr_reader name.to_sym instance_variable_set(“@#{var.to_s}”,[var.to_s]) end end class […]

Ruby CSV::Table sort in place

I’m sorting a CSV::Table object. I have a table with headers (“date”, “amount”, “source”) and O(50) entries. Input: data = CSV.table(‘filename.csv’, headers:true) # note headers are :date, :source, :amount amounts = [] data[:amount].each {|i| amounts << i.to_f} data.sort_by! {|row| row[:amount]} # error – not a defined function data = data.sort_by {|row| row[:amount]} # sorted but […]

How to add dynamic select menu in search form

I followed this railscast and successfully able to display countries and cities as dynamic select menu to choose the country and city on adding new profile. I have created a controller “search_controller.rb” with index action and a view “index.html.erb” in app/views/search. Now i want to create a search form in app/views/search/index.html.erb which have Autocomplete text […]

loops within ruby

Doing a very simple loop to display various data, for _test in @test … I want to be able to, 1) get the first value _test.name.first()??? 2) get the previous value(meaning, the last iteration, so I i iterated the first time, I want to grab it again, when its in the second loop Thank you […]

How to allow a user to login with user_name or email using Rails

I have been trying to give users the ability to sign-in using either their unique user_name or the email address they input while registering. Session_Controller.rb: class SessionsController < ApplicationController def create @user = User.where(email: params[:email]).first @user = User.where(username: params[:username]).first if @user.nil? if @user && @user.password == params[:password] session[:user_id] = @user.id flash[:notice] = “Successfully Logged In […]

How do I combine this Hash to a single JSON object?

I’m using the following code to generate a JSON file containing all category information for a particular website. The goal is to have a JSON file with the following format: [ { “id”:”36_17″, “name”:”Diversen Particulier”, “group”:”Diversen”, “search_attributes”:{ “0”:”Prijs van/tot”, “1”:”Groep en Rubriek”, “2”:”Conditie”, } }, { “id”:”36_18″, “name”:”Diversen Zakelijk”, “group”:”Diversen”, “search_attributes”:{ “0”:”Prijs van/tot”, “1”:”Groep en […]

Ruby 1.9 parse hash into an html table

I have a Ruby hash, for example: {“monkeys”=> {“hamburgers” => [“love”, “eat”], “boulders” => [“hate”, “throw”]}, “stonemasons” => {“boulders” = > [“love”, “use”], “vandals” => [“hate”, “sue”]} } It can have almost any level (I can put hashes inside hashes any number of times) of depth. It always has arrays as end values. How can […]

Ruby is the best programming language in the world - Ruby on Rails.