Question

I'm just starting to use Sequel in Ruby, and like it alot.

I want to pass a variable to the "from" method. So instead of calling a method like so:

DB.from(:items)

I'd like to call the method with a variable. For example:

# both of the following approaches fail
tableName = "items"
DB.from(tableName)
DB.from(:tableName)

But it fails with a sql error about a value that's not in my variable. I don't think this is a Sequel issue... I think it's a "I'm new to Ruby" issue.

How can I pass a variable to the from method above?

Was it helpful?

Solution

Do as below using String#to_sym method :

DB.from(tableName.to_sym)

Looking at the documentation of Sequel::Database#from, it seems it accepts all arguments as symbols. Thus you need to convert the string object pointed by the local variable tableName, to a symbol object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top