In Python there is vars() method which returns a dictionary of names of local variables as keys, and their values, so it is possible to do something like this:
a = 1
b = 2
"%(a)s %(b)s" % vars()
Is there an analog of vars() in Ruby? The closest construct I can think of is
local_variables.inject({}) {|res,var| res[var] = eval(var.to_...
I have a Rails App and users are pasting certain values from MS Word.
When I pasted this...
Paul’s “Test2”
This is what gets rendered in the app...
Paul’s “Testâ€
However, and this is the most bizarre aspect of this - this does not happen at once and I have not been able to track the specific circustances that leads to it.
So a ...
I'm writing my first Gem for a Rails project, and looking for in depth information about this topic i have found nothing at all.
I'm not looking "how to build a gem", but a relevant developer guide or resource on the topic (distributed programming with Ruby and so on).
I expect if someone have good reference material ??
Thanks in adva...
I think these three are the most popular non-relational db:s out there at this moment.
I want to give them a try, but I wonder which one of these are most suitable for Rails when it comes to Gem, documentation and tutorial support.
Eg. if I install a very good gem that is for Rails but this just use AR and mongodb, then it would be a p...
One of the challenges I see over and over again is a company with an existing website wants to integrate a Content Management System. Are there standard approaches/techniques for doing this that keep the existing website but allow certain pages or content snippets to be driven by the CMS?
For example let's say you have a Rails website t...
I've found some online interactive Javascript editors, but I wonder if there is a local equivalent as a gem that lets me test Javascript just like IRB and Rails console in Mac?
...
Hello guys
I'm currently modifying Liquid Framework (http://github.com/tobi/liquid) in order to make it support literals.
It's all nice and cool but I'm having a slight problem with the regexp I'm using. The following works great, except the fact that it captures the trailing space in $1
"{{{gnomeslab }}}" =~ /^(?:{{{\s?)(.*)(?:}}})$/...
I have a Sinatra based REST service app and I would like to call one of the resources from within one of the routes, effectively composing one resource from another. E.g.
get '/someresource' do
otherresource = get '/otherresource'
# do something with otherresource, return a new resource
end
get '/otherresource' do
# etc.
end
A ...
I have a database of 20k+ cities with latitude and longitude and I need to make lot of nearest point queries (which city is the nearest to certain lat,long point) against this dataset.
I guess an R-Tree or QuadTree would be a perfect data structure for this, but I haven't been able to find a working ruby implementation. Do you know any...
I'm testing some javascript libraries I've built by using ruby's harmony. Everything is working perfectly except AJAX calls — does anyone have any ideas how to achieve this?
My code looks something like this (I'm using RightJS):
my.js
function makerequest(argument) {
new Xhr('http://mysite.com/some/jsonp'),{
jsonp: true,
...
Hi
I want my text_field_tag to have the current date as a default value if the params for params[:date] is empty, here is my code at the moment:
<%= text_field_tag :end, params[:end] %>
i want somthing like: <%= text_field_tag :end, if params[:end] then use this value else show current date %>
thank you
...
I have this url in my database, in the "location" field:
http://www.youtube.com/watch?v=xxxxxxxxxxxxxxxxxxx
I can get it with @object.location, but how can I get the value of v? I mean, get "xxxxxxxxxxxx" from the url string?
Thanks and Regards.
...
MongoDB has two popular ORMs for Rails: MongoID and MongoMapper.
Are there CouchDB ORM:s for Rails 3?
...
This snippet throws an exception:
x = nil
jsoned = x.to_json
puts 'x.to_json=' + jsoned.inspect
puts 'back=' + JSON.parse(jsoned).inspect
C:/ruby/lib/ruby/1.9.1/json/common.rb:146:in `parse': 706: unexpected token at 'null' (JSON::ParserError)
x.to_json="null"
from C:/ruby/lib/ruby/1.9.1/json/common.rb:146:in `parse'
from C:/dev/p...
Using restful_authentication and
before_filter :login_required, :only=> [:create]
on controller:
Is it possible to store data from form, and after user logged in, continue with 'create'?
So i mean:
User logged off and he see Somecontroller#new
Then he fill in the form
Then he press "Save"
As we have login_required, user now has ...
xI've been working for days to get Twitter to authenticate with Ruby, but I'm not having any luck.
My first attempt was something like this:
class TwitterController < ApplicationController
def index
@callback_url = "http://dev.twipler.com:3000/twitter/auth"
@auth= TwitterOAuth::Client.new( :consumer_key => "xxx", :consumer_s...
It looks like in ruby 1.9.2 if to_s is defined, inspect will return to_s?? Why would this change?
This:
class ToSClass
def to_s
"#{self.class.name} to_s called"
end
end
class InspectClass
def inspect
"#{self.class.name} inspect called"
end
end
class BothClass
def inspect
"#{self.class.name} ...
I have a web page in java script on that i have elements which is a innertext of element that is in td tag.
...
Array#find_index allows you to find the index of the first item that either
is equal to an object, or
makes a block passed to it evaluate to true
Array#rindex can allow you to find the index of the last item that is equal to an object, but is there anything that allows you to find the index of the last item that makes a block passed...
I'm a Django person going into Rails, and I want a guide that shows me all the popular "conventions".
For example: plurality, _form.html.erb, stuff like that.
Can someone list them here? Or a webpage?
...