Simple code.please help me in debugging

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?

On Sat, Jan 7, 2012 at 10:40 AM, Libber [email protected]
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 S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan

On 7 January 2012 19:03, Hassan S. [email protected]
wrote:

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

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? *

@all:
Can you please suggest a good rails tutorial on using forms?

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 Y.

http://guides.rubyonrails.org/form_helpers.html
Ahmy Y.

On 8 January 2012 06:29, Libber [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs