How do I include the 'autofocus' attribute on an HTML5 form using the text_field form helper in ruby?
e.g. <%= f.text_field :email %
Where does autofocus go?
Thanks
Is there a better way to write this Expando class? The way it is written does not work.
I'm using Ruby 1.8.7
starting code quoted from https://gist.github.com/300462/3fdf51800768f2c7089a53726384350c890bc7c3
class Expando
def method_missing(method_id, *arguments)
if match = method_id.id2name.match(/(\w*)(\s*)(=)(\s*)(\.*)/)
puts match[1].to_sym # think this was supposed to be commented
self.class.class_eval{ attr_accessor match[1].to_sym }
instance_variable_set("#{match[1]}", match[5])
else
super.method_missing(method_id, *arguments)
end
end
end
person = Expando.new
person.name = "Michael"
person.surname = "Erasmus"
person.age = 29
In a simple Ruby example, I'm getting an error that does not occur in irb.
name = "Joe"
def say_hi
"\"Hi there!\" said #{self}"
end
response = name.say_hi
puts response
This code should return, "Hi there!" said Joe.
It works perfectly fine in irb. However, when I attempt to put the same code in a file and run the file, I get this error:
say_hi.rb:8:in `<main>': private method `say_hi' called for "Joe":String (NoMethodError)
Any suggestion about why this happens?
for instance in python it is possible to assign a method to a variable:
class MyClass
def myMethod(self):
return "Hi"
x = MyClass()
method = x.myMethod
print method() # prints Hi
I know this should be possible in Ruby, but I don't know what's the syntax.
So I know in ruby that x.nil? will test if x is null.
What is the simplest way to test if x equals ' ', or ' ', or ' ', etc?
Basically, I'm wondering what the best way to test if a variable is all whitespace?
Are there any logging frameworks in ruby that allow you to log a specific event type only once?
logger = IdealLogger.new
logger.log(:happy_path, "We reached the happy path") # => logs this message
logger.log(:happy_path, "We reached the happy path yet again") # => Doesn't log this
logger.log(:sad_path, "We've encountered a sad path!") # => logs this message
Also, is there a term for the concept of logging a certain event type only once?
Hi,
I write a little ruby script, which sends me an email when a new commit added to our svn.
I get the log with this code:
log = `/usr/bin/svnlook log #{ARGV[0]}`
When I run my script from bash I get good encoded character in the email, but when I try it and create a new commit I get wrong hungarian characters.
I commited this:
tes
oéá
I get this in the email:
Log: tes
?\197?\145?\195?\169?\195?\161
How can I solve this issue?
Is this a ruby bug?
target_url_to_edit = target_url
if target_url_to_edit.include?("http://")
target_url_to_edit["http://"] = ""
end
logger.debug "target url is now #{target_url}"
This returns target_url without http://
I want to have a "delete user" link in a normal Activerecord table, but I can't figure out how to wrangle the inline ruby in haml.
I have this:
%tbody
- @users.each do |user|
%tr
%td= user.name
%td= user.login
%td
%a
%img{:src => '../images/delete.png', :title => 'Delete user'}
How do I make the
- user.destroy
be a clickable link in Haml?
How to create a Qt GUI applications with the ability to access it from the ruby script.
Example:
require 'myQt'
myapp=myQt.new
myapp.startQtGuiApp
myapp.setValue('TextField1',45)
value=myapp.getValue('TextField2')
I'm processing huge data files (millions of lines each). Before I start processing I'd like to get a count of the number of lines in the file, so I can then indicate how far along the processing is. I am using Ruby, and because of the size of the files, it would not be practical to read the entire file into memory just to count how many lines there are. Does anyone have a good suggestion on how to do this?
I'm working on 2 cases:
assume I have those var:
a = "hello"
b = "hello-SP"
b = "not_hello"
1 - Any partial matches
I want to accept any string that has the var a inside, so b and c would match.
2 - Patterned match
I want to match a string that has a inside, followed by '-', so b would match, c does not.
I am having problem, because I always used the syntax /expression/ to define Regexp, so how dinamicaly define an RegExp on Ruby??
Is there an elegant way to check which port you deployed a ruby on rails application using mongrel? I could not find a directive (i.e. such as #{RAILS_ROOT} which contains the root directory of the application) that I can use to perform a check. I need this to do a check since I am deploying the same application on different ports and I need the app to do different things according to the port that is being accessed.
Any help would be appreciated,
Thanks
Given the Thread class with it current method.
Now inside a test, I want to do this:
def test_alter_current_thread
Thread.current = a_stubbed_method
# do something that involve the work of Thread.current
Thread.current = default_thread_current
end
Basically, I want to alter the method of a class inside a test method and recover it after that.
I know it sound complex for another language, like Java & C# (in Java, only powerful mock framework can do it). But it's ruby and I hope such nasty stuff would be available
I want to generate the Ruby documentation with hanna template.
How to do that? Or where can I download it if it's available at all?
Using
rdoc -o ~/doc --inline-source --line-numbers --format=html --template=hanna
gives me docs with missing methods. It seems like it doesn't generate methods written in C.
I'd like to run user supplied ruby code in server, what are the potentially nasty things that can happen? I mean things like deleting files etc. Can you give me more examples?
Thanks in advance!
How can I verify the certificates of a site like https://processing.ukash.com/ in ruby with net/http?
https = Net::HTTP.new('processing.ukash.com', 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
Works so far, but how do I verify that it's the right cert now? I saved the certificate from within firefox, but the resulting .pem file has many certificates in it and net/http doesn't seem to like it.
1)Url field should also accept url as “www.abc.com”. If user enters url like this, it should be automatically appended with “http://” resulting in value saved in database as “http://www.abc.com”. If user enters url as “http://www.xyz.com” system should not append “http://”. User should be able to save url with “https://”. what is the code for it in ruby on rails?
I'm trying to create a DSL in ruby, can you suggest me some good books? I looked around amazon and safari but so far couldn't find any.
Thanks in advance!
I've downloaded the "dbd-mysql-0.4.4.zip" and linked it to my project. While I try to run a demo code from NetBeans the very first line
require "dbi"
gives me an error. Is there a different way to do it?
I also tried
jruby setup.rb config --with=dbi,dbd_mysql
from the command prompt and it gave me the following error:
config: unknown option --with=dbi,dbd_mysql
Try 'ruby setup.rb --help' for detailed usage.
Any suggestions please?
The repr function is fancy as it is called when print OBJECT is used automatically?
Is there a ruby equivalence for it? I thought it was to_s, but, I had p OBJECT doesn't seem to call the to_s method.
Hi,
I'm starting learning Ruby on Rails. So my application, like every Rails app, has three databases:
Development
Test
Production
And the question is: how do i switch from a db to another?
Thanks
looper = (0..3).cycle
20.times { puts looper.next }
can I somehow find the next of 3? I mean if I can get .next of any particular element at any given time. Not just display loop that starts with the first element.
UPDATE
Of course I went though ruby doc before posting my question. But I did not find answer there ...