Dear all, In my web application, The client has to enter a set of values and I want to write them to a text file. This is what I am doing to achieve that. class SollusController < ApplicationController def index end def new @s=Sollu.new end def create @s=Sollu.new @s.save afile=File.open("network.txt",''w'') afile.write(@s.input) afile.close redirect_to sollus_path end def show end end But after I enter the values from the the browser, nothing gets saved in the file "network.txt". On the contrary, If I do this whole thing in ruby console as below, s=Sollu.new s.input="I need to write this to text file" afile=File.open("network.txt",''w'') afile.write(s.input) afile.close() After i run the above lines, I can see the text in the intended file. Can you please help me in debugging this part? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/kmEzliZQPqgJ. 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 Sat, Jan 7, 2012 at 10:40 AM, Libber <amarnath.alapati-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In my web application, The client has to enter a set of values and I > want to write them to a text file. This is what I am doing to achieve that.> def create > @s=Sollu.new > @s.save > afile=File.open("network.txt",''w'') > afile.write(@s.input) > afile.close > redirect_to sollus_path > end> But after I enter the values from the the browser, nothing gets saved in the > file "network.txt".No kidding. Where above do you imagine that `@s.input` is magically acquiring a value? You should run through a basic Rails tutorial on using forms... -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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.
On 7 January 2012 19:03, Hassan Schroeder <hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Jan 7, 2012 at 10:40 AM, Libber <amarnath.alapati-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> In my web application, The client has to enter a set of values and I >> want to write them to a text file. This is what I am doing to achieve that. > >> def create >> @s=Sollu.new >> @s.save >> afile=File.open("network.txt",''w'') >> afile.write(@s.input) >> afile.close >> redirect_to sollus_path >> end > >> But after I enter the values from the the browser, nothing gets saved in the >> file "network.txt". > > No kidding. Where above do you imagine that `@s.input` is magically > acquiring a value? > > You should run through a basic Rails tutorial on using forms...Also have a look at the Rails Guide on Debugging. That will show you how to use ruby-debug to break into your code and inspect data and follow the flow. Then you can break in before afile.write(@s.input) and you would see whether @s.input has any content. Colin -- 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.
Thanks for the reply guys...I figured out my error. I modified the code accordingly. Now I have a new problem..... In the create method, I call a system command to run a python program using the input from the user. The program executes perfectly but once the program executed, the server also stops. Here is the code, def create @s=Sollu.new(params[:sollu]) @s.save afile=File.open("network.txt",''w'') afile.write(@s.input) afile.close exec ''python netx.py'' ## *The server stops after executing this command. * image_tag "network_input.png" redirect_to sollus_path end *Basically what I want to do is, The client has to enter a data and using that I generate a image from the python code. I have to display that Image. If he is satisfied with the image, then he can choose to go further and save the data. Otherwise It has to redirect back to the new Sollu page and he should be given a option to change the previously entered data!. I am beginner and so all this questions. Any help on how should I write the code? * -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/DPTk7OTcxW4J. 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.
If im not mistaken , calling kernel#exec will replace current process (server). maybe this will help http://mentalized.net/journal/2010/03/08/5_ways_to_run_commands_from_ruby/ also I agree with hassan you should try to get familiar with rails first to get the feel of it. Ahmy Yulrizka On Sun, Jan 8, 2012 at 1:10 PM, Libber <amarnath.alapati-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The client has to enter a data and using that I-- 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.
@all: Can you please suggest a good rails tutorial on using forms? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/xP8pcXFjLagJ. 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.
http://guides.rubyonrails.org/form_helpers.html Ahmy Yulrizka On Sun, Jan 8, 2012 at 1:29 PM, Libber <amarnath.alapati-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @all: > Can you please suggest a good rails tutorial on using forms? >-- 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 8 January 2012 06:29, Libber <amarnath.alapati-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @all: > Can you please suggest a good rails tutorial on using forms?railstutorial.org covers most basic features of Rails and is free to use online. Make sure that any tutorial you use is for the version of Rails that you are using. Colin -- 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.