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@googlegroups.com.
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.

Search Discussions

  • Hassan Schroeder at Jan 7, 2012 at 7:03 pm

    On Sat, Jan 7, 2012 at 10:40 AM, Libber 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@gmail.com
    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@googlegroups.com.
    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.
  • Colin Law at Jan 7, 2012 at 8:37 pm

    On 7 January 2012 19:03, Hassan Schroeder wrote:
    On Sat, Jan 7, 2012 at 10:40 AM, Libber 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@googlegroups.com.
    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.
  • Libber at Jan 8, 2012 at 6:11 am
    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@googlegroups.com.
    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.
  • Ahmy Yulrizka at Jan 8, 2012 at 6:21 am
    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 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@googlegroups.com.
    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.
  • Libber at Jan 8, 2012 at 6:30 am
    @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@googlegroups.com.
    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.
  • Ahmy Yulrizka at Jan 8, 2012 at 6:50 am
    http://guides.rubyonrails.org/form_helpers.html
    Ahmy Yulrizka

    On Sun, Jan 8, 2012 at 1:29 PM, Libber 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@googlegroups.com.
    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.
  • Colin Law at Jan 8, 2012 at 8:21 am

    On 8 January 2012 06:29, Libber 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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 7, '12 at 6:40p
activeJan 8, '12 at 8:21a
posts8
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase