Is there any way I can parse a remote html page, in Ruby, preferably using jQuery like selectors?
For example, I could select all the div having a specific class, and get the content of all those elements in an array.
I was trying to use Regex for this, but I think using XML parser would be better.
...
I have a 2-d hash.I need to sort each sub-hash by value in descending order.
hsh={"a"=>{0=>1, 1=>2}}
output= {"a"=>{1=>2,0=>1}}
Thanks & Cheers !
...
Hi,
I am a beginner in Rails. In the following code,there is an id which is set as false. What's the meaning of it?
class CreateCoursesStudents < ActiveRecord::Migration
def self.up
create_table :courses_students, **:id => false** do |t|
t.integer :course_id,:null => false
t.integer :student_id, :null => false
...
For a specified model, I'd like to generate CREATE TABLE statements, in fact INSERT and UPDATE too, using a connection adapter which I specify. In other words I'd like to dump out a create table statement for a model for a particular database type. Is this possible?
...
I am trying to work with two worksheets at the same time.
So I have code
require 'parseexcel'
#Open the excel file passed in from the commandline
workbook = Spreadsheet::ParseExcel.parse(ARGV[0])
workbook2 = Spreadsheet::ParseExcel.parse(ARGV[1])
#Get the first worksheet
worksheet = workbook.worksheet(0)
worksheet2 = workbook2.worksh...
Is it possible to tell Ruby in Windows to use only \n instead of r\n?
I'm having an issue where a file is being saved with \r\n and it is causing it to not function properly. Is there a setting somewhere I can change to fix this?
...
Hello fellow stackoverflow members.
I have been following this guide to enable users to have their own avatar.
But i have bumped in to a litle problem.
When the user is cropping the image the model tries to validate all my validations.
My user model looks like this:
class User < ActiveRecord::Base
has_attached_file :avatar, :styles...
I am streaming wav data from a flash application. If I get the data and do the following:
f = File.open('c:/test.wav', 'wb')
f << wav_data.pack('c'*wav_data.length)
f.close
The wav file works perfectly. If I do this:
f = Tempfile.new('test.wav')
f << wav_data.pack('c'*wav_data.length)
f.close
FileUtils.mv(f.path, 'c:/')
The file is...
I'm trying to use unix sockets and SOCK_DGRAM in ruby, but am having a really hard time figuring out how to do it. So far, I've been trying things like this:
sock_path = 'test.socket'
s1 = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0)
s1.bind(Socket.pack_sockaddr_un(sock_path))
s2 = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM,...
I have a form with an ever-growing amount of associated javascript. At present this javascript lives in my form view which is fine, but it's getting larger and starting to overwhelm the form making it difficult to work on the form.
I want to put this in a separate file in my /public/javascripts directory but a lot of the javascript is g...
I have a model called List which has many records:
class List
has_many :records
end
class Record
end
The table Record has 2 permanent fields: name, email.
Besides these 2 fields, for each List a Record can have 'n' custom fields.
For example: for list1 I add address(text), dob(date) as custom fields.
Then while adding records to l...
I have a Ruby script that generates a ANSI file.
I want to converting ANSI to UTF8 file.
What's the easiest way to do it?
...
Im trying to get an 'add to cart' button to work. When I use <%= button_to "Add to Cart", :acton => "add_to_cart", :id => @product %> and then click the button, I get a URL that puts the action after the ID, like this: http://localhost:3000/store/show/1?acton=add_to_cart The cart page does not load.
What I need is a URL that looks li...
I have several methods I call from my controllers that feel like they should be pulled out and put into a reusable class, outside of the controller. Where do people usually put this stuff? I know I can put them into my ApplicationController, but that doesn't seem to be a great solution if I think I can use these methods later in other ap...
How to determine if a character is a chinese character use ruby?
...
What's Sinatra's equivalent of Rails' redirect_to method? I need to follow a Post/Redirect/Get flow for a form submission whilst preserving the instance variables that are passed to my view. The instance variables are lost when using the redirect method.
...
I will use it to do full text search in my ruby on rails app.
which is the best choice.
solr use java to do this job. or sphix in ruby?
...
Hi,
Anybody knows how to use sqlplus in ruby?
I need to do something like this:
system("sqlplus username/pwd@database filename.sql"
Thx
/Niklas
...
Consider the following code which is to be thrown at an AR find:
conditions = []
conditions[:age] = params[:age] if params[:age].present?
conditions[:gender] = params[:gender] if params[:gender].present?
I need to add another condition which is a LIKE criteria on a 'profile' attribute. How can I do this, as obviously a LIKE is usuall...
I have an issue when trying to set up rvm, where gems weren't installing due to them being dependent on json_pure. I tried to install json_pure, but rubygems itself seems to depend on json_pure. I have tried removing all versions of json_pure, but rubygems still complains.
$ sudo gem install json_pure
/Library/Ruby/Site/1.8/rubygems....