Hi, I'm new to rails and I would like to know how to make a form that submits to a database. I have tried devise but it seems that it deals with logins/users and it's not working for my purpose. I don't want anyone to do it for me, I have to learn :).
...
Hi,
I wrote this little application :
require 'rubygems'
require 'sinatra'
require 'bson'
require 'mongoid'
Mongoid.configure do |config|
name = "articles"
host = "localhost"
config.master = Mongo::Connection.new.db(name)
config.persist_in_safe_mode = false
end
class Article
include Mongoid::Document
field :title
field...
In IRB, I can do this:
c = /(\b\w+\b)\W*(\b\w+\b)\W*(\b\w+\b)\W*/.match(" !!one** *two* @@three@@ ")
And get this:
=> MatchData "one** *two* @@three@@ " 1:"one" 2:"two" 3:"three"
But assuming I don't know the number of words in advance, how can I still extract all words out of the string". For example, it might be " !!one** *two* @@...
How if at all can I use regex to match a string with a variable number of matches.
The strings I want to parse look like:
'Every 15th of the month'
'Every 21st and 28th of the month'
'Every 21st, 22nd and 28th of the month'
ad infinitum...
I want to be able to capture the ordinal numbers (15th, 21st etc)
The language I'm using is R...
I saw the code from here
Post.published.collect(&:views_count)
I guess it equals to
.collect { |p| p.views_count }
But I never saw this usage before, does this have a name? Where can I find more information about it?
...
Hi all,
I have one file named class1.rb this is structure
module Person
class Amit
def initialize
@a=10
end
end
end
another file named class2.rb
module Person
class Sumit < Amit
def aos
puts "#{@a}"
end
end
end
i am not able to acess variable @a in Sumit how do i do that??
...
We have a issue on our e-commerce site where users occasionally hit "checkout" twice and have their card charged twice.
It's a common enough bug and easy to fix, but I'd like to test the solution in our capybara setup. Once I've called click_button('checkout'), is it possible for me to pretend I'm a user hitting the browsers back button...
apt-get install ruby
Installs ruby 1.8.7
When I install ruby 1.9.2 from sources via ./configure make install, ruby is not installed (ruby -v gives nothing).
So how can I install ruby 1.9.2 on Ubuntu?
...
Hello. Me and a colleage are working in different projects that share some models. So, we are sharing the models thru a git submodule.
Additionally, we'd like to be able to also share migrations:
In this way, my collegue's migrations would be in the folder db/migrate/other_db of my project.
How can I configure rails migrations to also...
can we load seed data when start cucumber?
Please support me a way.
...
There are 2 servers, they need to know the status(live oe dead) each other. my method is a long tcp connecting, Is there any better method? thanks.
...
Hi All,
I want to get class methods in an object. Please see the following example
I have a class "user.rb"
class User
def say_name
end
def walk(p1)
end
def run(p1, p2)
end
end
and I wrote the following code
require 'user.rb'
a = User.new
arr = a.public_methods(all = false)
Above code will return the method ...
Hi,
an important part of my project is to log in into remote server with ssh and do something with files on it:
Net::SSH.start(@host, @username, :password => @password) do |ssh|
ssh.exec!(rename_files_on_remote_server)
end
How to test it?
I think I can have local ssh server on and check file names on it (maybe it could be in my t...
What is the smartest way to find out if a PNG has transparency or not in Ruby? Is it OK if I just check if there's an alpha-channel? If yes: How do I check for an alpha-channel?
I'm writing a script that will convert all PNGs without transparency into smaller JPGs.
Thanks a lot for your help!
...
Let's assume text is a String and contains a text. tags is an Array of Strings.
text = <<-EOS
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.
Duis au...
How do you build a model with the following associations (i tried but couldn't get it to work):
each Order has: a Customer, a SalesRep, many OrderLine that each has an item.
I tried: when I do: Customer.all(Customer.orders.order_lines.item.sku.like => "%BLUE%")
the output is :[]
instead of: '[#<"Customer @id=1 @name="Dan Kubb">]'
Whe...
Using Mongoid, let's say I have the following classes:
class Map
include Mongoid::Document
embeds_many :locations
end
class Location
include Mongoid::Document
field :x_coord, :type => Integer
field :y_coord, :type => Integer
embedded_in :map, :inverse_of => :locations
end
class Player
include Mongoid::Document
...
Some popular blog sites typically use square brackets in their URLs but ruby's built-in URI.parse() method chokes on them, raising a nasty exception, as per:
http://redmine.ruby-lang.org/issues/show/1466
I'm trying to write a simple monkey-patch that gracefully handles URLs with the square bracket. The following is what I have so far:
...
I have this data and i need an output like this type of output.. I basically need to have all the venues and their dates and all the songs associated to them ....if anyone can think of a better structure and how to achieve it I would be very thankful...
{
["Vector Arena - Auckland Central, New Zealand" =>
{
"2010-10-10" => ["...
I'm trying to test a method on my model. Running in the console works, but my rspec test does not pass. Checkout the code:
Model:
def import(master)
hsh = master.attributes.delete_if { |k,v| k == 'id' }
self.update_attributes(hsh)
end
Rspec test:
describe "#import" do
let(:master) { Factory(:sheet, :work_order => 'M1234', :sa...