Ruby: convert proc to lambda?
...
I'm very new with rails and I've been building a CMS application backend. All is going well, but I would like to know if this is possible? Basically I have two models: @page { id, name, number } @extended_page { id, page_id, description, image } The idea is that there are bunch of pages but NOT ALL pages have extended_content. In t...
I want to start my daemon with my application. In the command line, I can write something like lib/daemons/mydaemon_ctl start to start up my daemon, but I have to do this manually. I want the daemon to start when I start my server (i.e. when the initializer files are loaded). Is there a ruby command for executing a command line? Someth...
I am trying to push my app to heroku and I get the following message: $ heroku create Creating electric-meadow-15..... done Created http://electric-meadow-15.heroku.com/ | [email protected]:electric-meadow-1 5.git $ git push heroku master ! No such app as fierce-fog-63 fatal: The remote end hung up unexpectedly It's weird that I am...
I have a daemon that I'm starting along with the server using an initializer file. I want to stop this daemon once the server stops, but I'm not sure where to put a script that would run when the server stops. Initializers get automatically loaded when the server starts. Is there a similar "destroyers" folder? Where would I put code tha...
I have two arrays, each holding arrays with attribute hashes. Array1 => [[{attribute_1 = A}, {attribute_2 = B}], [{attribute_1 = A}, {attribute_4 = B}]] Array2 => [{attribute_3 = C}, {attribute_2 = D}], [{attribute_3 = C, attribute_4 = D}]] Each array in the array is holding attribute hashes for an object. In the above example, the...
I have a XML File in the following format: <?xml version='1.0' encoding='UTF-8'?> <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009' xmlns:app='http://www.w3.org/2007/app' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/"DUYGRX85fCp7I2A9WxFWEkQ."'><id>https...
I'm currently modifying my regex for this: http://stackoverflow.com/questions/2782031/extracting-email-addresses-in-an-html-block-in-ruby-rails basically, im making another obfuscator that uses ROT13 by parsing a block of text for all links that contain a mailto referrer(using hpricot). One use case this doesn't catch is that if the us...
Is there a way for programmatically accessing a method comments? or an attribute comments? I would like to use it as a description for the method in a documentation which I don't want to be static or generated with rdoc or equivalent. Here is an example of a Ruby class: Class MyClass ## # This method tries over and over until it i...
I'm looking for an image url helper for sinatra that allows me to do something similar to staticmatic's, where I can shortcut to a relative path like so... =img "me.jpg" Can anybody point me in the direction to where this might be online, or where I could learn how to write one, or provide an example of one they have already written ...
i have Product and SalesOrder model (to simplify, 1 sales_order only for 1 product) Product has_many :sales_orders SalesOrder belongs_to :product pa = Product A #2000 so1 = SalesOrder #1 order product A #1000, date:yesterday so2 = SalesOrder #2 order product A #999, date:yesterday so3 = SalesOrder #3 order product A #1000, date:now...
How could one do switch in ruby on rails something like: case controller "home" do home case controller "about" do about else do home I currently have this code: <% case current_page(:controller) %> <% when "forums" %> <%= render :partial => 'shared/sidebar/sidebar_forums' %> <% when "events" %> ...
Right now, I do a get '/' do set :base_url, "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}" # ... haml :index end to be able to use options.base_url in the HAML index.haml. But I am sure there is a far better, DRY, way of doing this. Yet I cannot see, nor find it. (I am new to Sinatra :)) Somehow, outside of...
Over the last few months, there have been a number of rapid developments in the state of Ruby dependency management and gem creation, to the point where I've been having trouble keeping up with everything. If I'm writing a new gem, what's the best tool for me to use to create my gemspec? Are there disadvantages of using this tool over ...
I want to upload a video file and convert it to flash and 3gp/mp4. No problem, plenty of tuts for this out there using paperclip and ffmpeg. For some reason I thought there was a tut that showed if std browser play flv but if mobile then use 3gp/mp4 but can't seem to find it. Any one know if there is a tut like this out there? Else, ...
Some time ago I had a look into Ruby and one of the things which stood out most for me was the way of using symbols. While you to use defines or strings like in C++ or Python as an alternative, in Ruby you just write :mySymbol and the interpreter takes over the enumeration for you. I can't see any disadvantage this feature has, so why...
I have a sample position file like below. 789754654 COLORA SOMETHING1 19370119FYY076 2342423234SS323423 742784897 COLORB SOMETHING2 20060722FYY076 2342342342SDFSD3423 I am interested in positions 54-61 (4th column). I want to change the date to be a different format. So final outcome will be: ...
I just started out using IronRuby (but the behaviour seems consistent when I tested it in plain Ruby) for a DSL in my .NET application - and as part of this I'm defining methods to be called from the DSL via define_method. However, I've run into an issue regarding optional parens when calling methods starting with an uppercase letter. ...
i am using the facebooker gem from http://github.com/mmangino/facebooker for developing a rails 2 facebook application (iframe). i am wondering if this is a bug from facebooker: when i am using ensure_application_is_installed_by_facebook_user in the application controller, the iframe gets rendered in an infinite loop. i found out tha...
I've got a simple active record validation on an object using this within a form: form.error_messages({:message => '', :header_message => ''}) This in turn outputs something like "FieldName My Custom message" What i need to do is remove the field name from the error message but leave my custom message. Can anyone point me in the r...