rubynewbie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-05 11:40 UTC
Executing .rb file within view
Hello everyone, I need to execute a ruby script from within my view. It''s a script that dynamically generates an image as output, so the invocation should look something like this: <%= image_tag "/images/myScript.rb?args=foobar"%> Now I don''t know how to configure WEBrick to execut the ruby file when I put it in my project folder in public/images and access it through localhost:3000/project/images/myScript.rb When doing so, my browser displays the source of myScript.rb instead of executing it. Another possibility would certainly be to run my script as a webserver on a different port and invoking it like this: <%= image_tag "localhost:3001/myScript.rb?args=foobar"%> but a second server running seems to be a little bit of overkill to me. I''d apreciate any suggestions. If there is any better way to do this, please let me know. Thanks a lot, Frank --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
On 11/5/07, rubynewbie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <frank.preiswerk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello everyone, > > I need to execute a ruby script from within my view. It''s a script > that dynamically generates an image as output, so the invocation > should look something like this: > <%= image_tag "/images/myScript.rb?args=foobar"%> > > Now I don''t know how to configure WEBrick to execut the ruby file when > I put it in my project folder in public/images and access it through > localhost:3000/project/images/myScript.rb > When doing so, my browser displays the source of myScript.rb instead > of executing it. > > Another possibility would certainly be to run my script as a webserver > on a different port and invoking it like this: > <%= image_tag "localhost:3001/myScript.rb?args=foobar"%> > but a second server running seems to be a little bit of overkill to > me. >You could use rails and call your script from a controller then render it : render :text => result_from_script or render :inline => result_from_script -- Fabien Jakimowicz --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
rubynewbie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-05 12:06 UTC
Re: Executing .rb file within view
thanks for the quick reply. this approach may insert some external HTML or whatever into my final output to the browser, but I cannot embed the image like this, right? The idea is to invoke the script from the client and produce a HTML response followed by the image data. The reason for this is because the image is not saved as a file (for performance), so I have to directly send it to the client after computation. frank On Nov 5, 12:47 pm, "Fabien Jakimowicz" <fab...-SKT9N6NoqVlE4Z/KZFzVqg@public.gmane.org> wrote:> On 11/5/07, rubynew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <frank.preisw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hello everyone, > > > I need to execute a ruby script from within my view. It''s a script > > that dynamically generates an image as output, so the invocation > > should look something like this: > > <%= image_tag "/images/myScript.rb?args=foobar"%> > > > Now I don''t know how to configure WEBrick to execut the ruby file when > > I put it in my project folder in public/images and access it through > > localhost:3000/project/images/myScript.rb > > When doing so, my browser displays the source of myScript.rb instead > > of executing it. > > > Another possibility would certainly be to run my script as a webserver > > on a different port and invoking it like this: > > <%= image_tag "localhost:3001/myScript.rb?args=foobar"%> > > but a second server running seems to be a little bit of overkill to > > me. > > You could use rails and call your script from a controller then render it : > render :text => result_from_script > or > render :inline => result_from_script > > -- > Fabien Jakimowicz--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
rubynewbie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-05 12:20 UTC
Re: Executing .rb file within view
I have just discovered the "send_data" method which seems to do exactly what I need: send a string containing binary data to the client. It even lets me specify the content type, so it''s perfect for my purpose. I''ll try it out and let you know if it worked out. Frank On Nov 5, 1:06 pm, "rubynew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <frank.preisw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> thanks for the quick reply. > this approach may insert some external HTML or whatever into my final > output to the browser, but I cannot embed the image like this, right? > The idea is to invoke the script from the client and produce a HTML > response followed by the image data. The reason for this is because > the image is not saved as a file (for performance), so I have to > directly send it to the client after computation. > > frank > > On Nov 5, 12:47 pm, "Fabien Jakimowicz" <fab...-SKT9N6NoqVlE4Z/KZFzVqg@public.gmane.org> wrote: > > > On 11/5/07, rubynew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <frank.preisw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hello everyone, > > > > I need to execute a ruby script from within my view. It''s a script > > > that dynamically generates an image as output, so the invocation > > > should look something like this: > > > <%= image_tag "/images/myScript.rb?args=foobar"%> > > > > Now I don''t know how to configure WEBrick to execut the ruby file when > > > I put it in my project folder in public/images and access it through > > > localhost:3000/project/images/myScript.rb > > > When doing so, my browser displays the source of myScript.rb instead > > > of executing it. > > > > Another possibility would certainly be to run my script as a webserver > > > on a different port and invoking it like this: > > > <%= image_tag "localhost:3001/myScript.rb?args=foobar"%> > > > but a second server running seems to be a little bit of overkill to > > > me. > > > You could use rails and call your script from a controller then render it : > > render :text => result_from_script > > or > > render :inline => result_from_script > > > -- > > Fabien Jakimowicz--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
rubynewbie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-05 18:25 UTC
Re: Executing .rb file within view
it worked out pefectly. I created an additional controller that solely returns the image using send_data() instead of rendering any template. thanks for your help. frank On Nov 5, 1:20 pm, "rubynew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <frank.preisw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have just discovered the "send_data" method which seems to do > exactly what I need: send a string containing binary data to the > client. It even lets me specify the content type, so it''s perfect for > my purpose. > I''ll try it out and let you know if it worked out. > > Frank > > On Nov 5, 1:06 pm, "rubynew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <frank.preisw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > thanks for the quick reply. > > this approach may insert some external HTML or whatever into my final > > output to the browser, but I cannot embed the image like this, right? > > The idea is to invoke the script from the client and produce a HTML > > response followed by the image data. The reason for this is because > > the image is not saved as a file (for performance), so I have to > > directly send it to the client after computation. > > > frank > > > On Nov 5, 12:47 pm, "Fabien Jakimowicz" <fab...-SKT9N6NoqVlE4Z/KZFzVqg@public.gmane.org> wrote: > > > > On 11/5/07, rubynew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <frank.preisw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hello everyone, > > > > > I need to execute a ruby script from within my view. It''s a script > > > > that dynamically generates an image as output, so the invocation > > > > should look something like this: > > > > <%= image_tag "/images/myScript.rb?args=foobar"%> > > > > > Now I don''t know how to configure WEBrick to execut the ruby file when > > > > I put it in my project folder in public/images and access it through > > > > localhost:3000/project/images/myScript.rb > > > > When doing so, my browser displays the source of myScript.rb instead > > > > of executing it. > > > > > Another possibility would certainly be to run my script as a webserver > > > > on a different port and invoking it like this: > > > > <%= image_tag "localhost:3001/myScript.rb?args=foobar"%> > > > > but a second server running seems to be a little bit of overkill to > > > > me. > > > > You could use rails and call your script from a controller then render it : > > > render :text => result_from_script > > > or > > > render :inline => result_from_script > > > > -- > > > Fabien Jakimowicz--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---