On Jan 16, 1:18 pm, "Michael Libby" <[email protected]> wrote:
> On Fri, Jan 16, 2009 at 10:32 AM, naevity <[email protected]> wrote:
>
> > Is this even possible? I've got a ruby expression stored in a
> > database, it's the code to run a plugin since I was having trouble
> > passing variables stored in the database.
>
> In my opinion it would be better to solve the original problem you had
> with the plugin and passing variables than to use dynamically executed
> code as a workaround. From your snippets I'd guess the problem is you
> are trying to save/pass a string like "Gbarcode::BARCODE_128" into the
> plugin rather than the underlying value referred to by the constant
> Gbarcode::BARCODE_128.
Thank's for the response Michael and Robby, here's my response before
I saw what Michael wrote:
> This smells funny... so I wanted to ask for more information. How is
> the ruby code going to be added into the database? Would users be
> inputting ruby code somehow?
Well, it's a workaround to another problem I'm running into. I'm
trying to use the barcode-generator plugin (http://code.google.com/p/
barcode-generator/), which is based on the gbarcode gem.
In my database I have two tables, one for the numbers, and one for the
types of codes
to use the plugin, you call <%= barcode 'UPCCODE' %> in the view, and
it generates the code to create and display the PNG. My problem is
that I'm trying to add the :encoding_function option to the code,
which would look something like this:
<%= barcode 'UPCCODE', :encoding_function => Gbarcode::BARCODE_ISBN %>
I need to be able to dynamically input the encoding function like
this:
<%= barcode code.number, :encoding_function => code.type.upctype %>
but this pops up errors.
I've tried every combination of trying to pass that value, and it
always fails. So, as a last resort, I wrote code to just write the
whole line to the database for each UPCnumber, i.e.:
<%= barcode 'TEST1234', :encoding_function => Gbarcode::BARCODE_39 %>
<%= barcode '234567890987', :encoding_function =>
Gbarcode::BARCODE_ISBN %>
<%= barcode 'U567890298322E', :encoding_function =>
Gbarcode::BARCODE_128 %>
But, as I said above, when I try to pull this code, and run it to
generate and display the barcode, it fails.
For Example:
code: <%= barcode card.cardnumber, :encoding_format =>
card.rewards.upctype %>
code.type.upctype: Gbarcode::BARCODE_ISBN
result: in method 'Barcode_Encode', argument 2 of type 'int'
code: <%= barcode card.cardnumber, card.rewards.upctype %>
code.type.upctype: :encoding_format => Gbarcode::BARCODE_ISBN
result: index 94105 out of string
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---