Hi, Im passing an object as follows. Controller: def new @c = Check.first end View: <form action="create" method="post"> <%= hidden_field_tag "checks", @c %> <%= submit_tag "submit" %> </form> The params i get in create method is, {"checks"=>"#<Check:0xa2c3134>", "commit"=>"submit"} Any idea how to parse "#<Check:0xa2c3134>" and take all the data? Thanks, Srikanth J -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Srikanth, Are you looking to parse individual attributes of Check to your create method or do you want to do the manipulations in create? In your create method, you can just do something like: def create @check = params[:checks] # and then you can manipulate it here # @check.inspect end Hope this helps. Cheers, David Chua http://flavors.me/davidchua | http://dchua.com | @davidchua On Tue, Feb 8, 2011 at 3:20 PM, Srikanth Jeeva <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > Im passing an object as follows. > > Controller: > > def new > @c = Check.first > end > > View: > > <form action="create" method="post"> > <%= hidden_field_tag "checks", @c %> > <%= submit_tag "submit" %> > </form> > > The params i get in create method is, > {"checks"=>"#<Check:0xa2c3134>", "commit"=>"submit"} > > Any idea how to parse "#<Check:0xa2c3134>" and take all the data? > > Thanks, > Srikanth J > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
what you see in the params is not the Check object but it''s string representation. There is no sane way to get the actual object out of this. I guess what you want is to pass the id of the check object and not the object itself. <%= hidden_field_tag "checks", @c.id %> and in the controller def create @check = Check.find(params[:checks]) end -- pascal On Feb 8, 9:20 am, Srikanth Jeeva <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > Im passing an object as follows. > > Controller: > > def new > @c = Check.first > end > > View: > > <form action="create" method="post"> > <%= hidden_field_tag "checks", @c %> > <%= submit_tag "submit" %> > </form> > > The params i get in create method is, > {"checks"=>"#<Check:0xa2c3134>", "commit"=>"submit"} > > Any idea how to parse "#<Check:0xa2c3134>" and take all the data? > > Thanks, > Srikanth J > > -- > Posted viahttp://www.ruby-forum.com/.-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi David,> def create > @check = params[:checks] > # and then you can manipulate it here > # @check.inspect > end@check.inspect gives me,.. "#<Check:0xa2c3134>" any idea how can i make it {"name" => "XXX", "number" => "YYY"} Thanks, Srikanth -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Pascal,> what you see in the params is not the Check object but it''s string > representation. > There is no sane way to get the actual object out of this. I guess > what you want is > to pass the id of the check object and not the object itself.for example of object i made it @c = Check.first. Actually its @c = Check.new @c.name = "Srikanth" @c.number = 1234 And i need this object in create. Thanks, Srikanth -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Oh I''m sorry, I didn''t quite understand your question earlier, its clearer now. What you can consider doing is attaching the Check object''s id into the hidden_field, and then pass the id into your create method. Then all you need to do is to use ActiveRecord to retrieve that Check object with your id. David On Tue, Feb 8, 2011 at 5:13 PM, Srikanth Jeeva <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi Pascal, > > > what you see in the params is not the Check object but it''s string > > representation. > > There is no sane way to get the actual object out of this. I guess > > what you want is > > to pass the id of the check object and not the object itself. > > for example of object i made it @c = Check.first. > > Actually its > > @c = Check.new > @c.name = "Srikanth" > @c.number = 1234 > > And i need this object in create. > > Thanks, > Srikanth > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> What you can consider doing is attaching the Check object''s id into the > hidden_field, and then pass the id into your create method.Actually there was no id for that object. I did like this. converted to json and parsed it. def new @c = Check.new @c.name = "Srikanth" @c.number = 1234 @a = @c.to_json end And in View: <%= hidden_field_tag "checks", @a %> def create p = JSON.parse(params[:checks]) puts p.inspect end got p as, {"check"=>{"name"=>"Srikanth", "number"=>1234}} Thanks all for reply. -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You can also try using <%= hidden_field_tag ''checks[name]'', @c.name %> <%= hidden_field_tag ''checks[number]'', @c.number %> So you don''t have to parse it in the create action. On Tue, Feb 8, 2011 at 6:51 PM, Srikanth Jeeva <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > What you can consider doing is attaching the Check object''s id into the > > hidden_field, and then pass the id into your create method. > > Actually there was no id for that object. > > I did like this. converted to json and parsed it. > > def new > @c = Check.new > @c.name = "Srikanth" > @c.number = 1234 > @a = @c.to_json > end > > And in View: > <%= hidden_field_tag "checks", @a %> > > def create > p = JSON.parse(params[:checks]) > puts p.inspect > end > > got p as, > {"check"=>{"name"=>"Srikanth", "number"=>1234}} > > Thanks all for reply. > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.