I''m stuck in trying to get an embedded expression in ERB. I''m trying to put @post into @httppost. However when I print @httppost I get (notice the @post): {"aps": {"badge": 1, "alert", #{@post}}, "sound": "cat.caf", "device_tokens": ["455ab1b23cbfd97b7d2ef90a49d222e40f4c6c9b2570e84ff94fe4afeea12345"]} It should say: {"aps": {"badge": 1, "alert", "This is a test"}, "sound": "cat.caf", "device_tokens": ["455ab1b23cbfd97b7d2ef90a49d222e40f4c6c9b2570e84ff94fe4afeea12345"]} I put everything in my view to make it easier to troubleshoot: <% @post = params[:post] %> post params: <%= @post %> <br /> <% @httppost = ''{"aps": {"badge": 1, "alert", "#{@post}"}, "sound": "cat.caf", "device_tokens": ["455ab1b23cbfd97b7d2ef90a49d222e40f4c6c9b2570e84ff94fe4afeea12345"]}'' %> <%= @httppost %> You can see the enclosed screen capture to see what my results are. Thanks in advance. Attachments: http://www.ruby-forum.com/attachment/4535/Screen_shot_2010-03-04_at_4.24.40_PM.png -- 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.
On Mar 4, 2010, at 4:27 PM, Allan Last wrote:> I''m stuck in trying to get an embedded expression in ERB. > > I''m trying to put @post into @httppost. However when I print > @httppost I > get (notice the @post): > {"aps": {"badge": 1, "alert", #{@post}}, "sound": "cat.caf", > "device_tokens": > ["455ab1b23cbfd97b7d2ef90a49d222e40f4c6c9b2570e84ff94fe4afeea12345"]} > > > It should say: > {"aps": {"badge": 1, "alert", "This is a test"}, "sound": "cat.caf", > "device_tokens": > ["455ab1b23cbfd97b7d2ef90a49d222e40f4c6c9b2570e84ff94fe4afeea12345"]} > > > > I put everything in my view to make it easier to troubleshoot: > > <% @post = params[:post] %> > > post params: <%= @post %> > > <br /> > > <% @httppost = ''{"aps": {"badge": 1, "alert", "#{@post}"}, "sound": > "cat.caf", "device_tokens": > ["455ab1b23cbfd97b7d2ef90a49d222e40f4c6c9b2570e84ff94fe4afeea12345"]}'' > %>You''ve got it wrapped in single quotes... which won''t interpolate. You want double quotes... or in your case since you''ve got a lot of double quotes you probably don''t want to escape... use the %Q method... <% @httppost = %Q!{"aps": {"badge": 1, "alert", "#{@post}"}, "sound": "cat.caf", "device_tokens": ["455ab1b23cbfd97b7d2ef90a49d222e40f4c6c9b2570e84ff94fe4afeea12345"]}! The ''!'' can be whatever you want (I think) so pick something that isn''t in your string. If it''s paired (ie %Q{...}) use the opening/ closing keys. -philip> <%= @httppost %> > > You can see the enclosed screen capture to see what my results are. > Thanks in advance. > > Attachments: > http://www.ruby-forum.com/attachment/4535/Screen_shot_2010-03-04_at_4.24.40_PM.png > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@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.
Philip, Thanks a lot! This really helped me! -A Philip Hallstrom wrote:> On Mar 4, 2010, at 4:27 PM, Allan Last wrote: > >> It should say: >> post params: <%= @post %> >> >> <br /> >> >> <% @httppost = ''{"aps": {"badge": 1, "alert", "#{@post}"}, "sound": >> "cat.caf", "device_tokens": >> ["455ab1b23cbfd97b7d2ef90a49d222e40f4c6c9b2570e84ff94fe4afeea12345"]}'' >> %> > > You''ve got it wrapped in single quotes... which won''t interpolate. > You want double quotes... or in your case since you''ve got a lot of > double quotes you probably don''t want to escape... use the %Q method... > > <% @httppost = %Q!{"aps": {"badge": 1, "alert", "#{@post}"}, "sound": > "cat.caf", "device_tokens": > ["455ab1b23cbfd97b7d2ef90a49d222e40f4c6c9b2570e84ff94fe4afeea12345"]}! > > The ''!'' can be whatever you want (I think) so pick something that > isn''t in your string. If it''s paired (ie %Q{...}) use the opening/ > closing keys. > > -philip-- 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.