mrudult
mrudult

Reputation: 2570

Parse a ruby object sent from a form in rails

I'm trying to pass an object through a form like this:

<%= simple_form_for :export, url: export_path(format: :xls,data: @result) do |f| %>
 ### fields
<% end %>  

But I'm getting the object as a string and so I'm not able to access it. How do I convert the passed string to object?

I'm getting:

undefined method something for "Mongoid::Criteria:0x00000105f75818":String

Update

I found out that this is a really bad way of passing object via a form. Instead, I sent all the id's concerning the @result object and recreated the result object server side. That solved my problem.

Upvotes: 2

Views: 74

Answers (1)

Raj
Raj

Reputation: 22926

There are few options for you:

  • Don't send the @result via form. Have it in the server(as file/database record) and read only the column list from the form
  • Use only the required string portion of @result in your form
  • If you need the entire object, serialize your @result object and pass via form. Deserialize back in the server. Use something like Marshal.

Upvotes: 4

Related Questions