I have a helper module with a bunch of method calls in the format
def link_to_details_for_facebook(param1, param2)
def link_to_details_for_twitter(param1, param2)
def link_to_content_for_facebook(param1, param2)
def link_to_content_for_twitter(param1, param2)
is there a way to call one method such as, so I can dynami...
When I run mongrel_rails start for my application, I get the following error:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/http11.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10]
I am running Snow Leopard and Ruby, Rails, and PostgreSQL 8.4 v...
I need to set an HTML class to this rails select and i have tried many variations and nothing
<%= add.select :state,
@states.map { |s| [ s.name, s.abbr ] },
:class => 'state',
:include_blank => true
%>
...
My implementation of markdown turns double hyphens into endashes. E.g., a -- b becomes a – b
But sometimes users write a - b when they mean a -- b. I'd like a regular expression to fix this.
Obviously body.gsub(/ - /, " -- ") comes to mind, but this messes up markdown's unordered lists – i.e., if a line starts - list item, it will beco...
Hi there,
I was wondering how can I get the inverse of power in ruby?
2 ** 4 => 16
and then I would like to get the inverse of it, and I'm not sure which operator to use :(
16 ?? 2 => 4
Thanks a lot
...
On the last two lines:
$ ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10]
$ irb
irb(main):001:0> def t(str)
irb(main):002:1> str.index str
irb(main):003:1> end
=> nil
irb(main):004:0> t 'abc'
=> 0
irb(main):005:0> t "\x01\x11\xfe"
=> nil
irb(main):006:0> t "\x01\x11\xfe".force_encoding(Encoding::UTF_8)
=> nil
Why do...
I have a bunch of posts written in markdown and I need to remove the periods from the end of every paragraph in each of them
The end of a paragraph in markdown is delimited by:
2 or more \ns or
The end of the string
However, there are these edge cases
Ellipses
Acroynms (e.g., I don't want to drop the final period in "Notorious B.I...
I recently ran into code that looks like this:
next {
'foo' => bar,
'foobar' => anotherbar,
}
At first it looks like a simple hash, but there is no assignment to next. Next in this case looks like a reserved Ruby keyword. What does this code do?
...
I have a test class which i want to add to another test suite ..
I tried testsuite<
am i doing something wrong in here
...
I'm thinking of writing a basic ruby debugger (interactive), Can you direct me to some resources or projects to learn more?
Thanks in advance!
...
Let's say I have methodA
def methodA
note = Note.find(params[:id])
note.link = params[:link]
note.linktype = params[:linktype]
note.save
redirect_to(notes_url)
end
When I call this method from a view like this, it works fine
<%= link_to image_tag(w.link, :border =>0), methodA_path(:linktype => w.linktype, :lin...
i am including my own .rb(HintsHelper.rb) file on view. But it gives the following error. Why?
uninitialized constant ActionView::Base::CompiledTemplates::HintsHelper
then...
i included HintsHelper.rb in Application Helper file. but still it is giving me the following error.
uninitialized constant ApplicationHelper::HintsHelper
How to...
I'm running into an error when I try to split the dm-observer class into a separate file from my model class. Previously it worked fine if I put it all into a single file.
# test_observer.rb
require 'dm-observer'
class TestObserver
include DataMapper::Observer
observe Test
before :create do
# does funky stuff
end
end ...
Before I start, I apologize for a bad title but I could not come up with one that describes my question in a satisfying way. If you come up with a better title, I will gladly switch.
Suppose I have an Account model and a Transaction model, and I would like to implement a Account#days_since_balance_was_atleast method, taking a sum as its...
Standard curl supports command line option --trace-asci and --trace. Anyone any clues on how to set this option for a Curl::Easy object?
...
i have a file named ama.txt and content of the file is like
name age hobby sex
amit 45 music male
sumit 35 cricket female
now i just open like
File.open("ama.txt").each do
end
now how can i modified hobby column of file
...
I want to test if I have 0, 1, 2 or 3 times a pictures ('foo.png') in a certain page with Cucumber.
How should I write the custom step?
Thanks
...
I have a Rails project with lots and lots of cyrillic strings in it.
It worked fine on Ruby 1.8, but Ruby 1.9 recognizes all source files as US-ASCII-encoded until you provide an # encoding: utf-8 comment on top of each and every source file in the project. Obviously the files don't parse as US-ASCII.
Is there a simpler way to say, li...
I need an SQL statement that check if one condition is satisfied:
SELECT * FROM my_table WHERE my_table.x=1 OR my_table.y=1
I want to do this the 'Rails 3' way. I was looking for something like:
Account.where(:id => 1).or.where(:id => 2)
I know that I can always fallback to sql or a conditions string. However, in my experience this...
Model
def before_save
self.default_file_name = "#{self.model_name.underscore}.csv" if self.default_file_name.nil?
self.default_directory_name = "public/uploads" if self.default_directory_name.nil?
verify_methods
verify_record
end
def verify_methods
self.errors.add_to_base(_("Invalid row instance method.")) \
if !self.each_r...