I currently have javascript in my view and it contains inputs so users
can input values

<input type = "text" name = "date8" id = "date8" value = "" size =25 >

I want to be able to access the value in this input once a method in my
controller is called. How can I do this? params[date8] does not work
which makes sense since it isnt a ruby textfield. Anyone have any ideas?
Thanks

--
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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Yong Gu at Apr 19, 2013 at 3:12 pm
    It depends how you send that value to the controller.

    If you use a form to submit data, then params[:date8] would work.

    If you use a link, then you need to append the value to the link, like http://www.yourdomain.com/controller/method?date8=value

    --
    Yong Gu
    Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

    On Friday, April 19, 2013 at 11:03 PM, Ronald Zhang wrote:

    I currently have javascript in my view and it contains inputs so users
    can input values

    <input type = "text" name = "date8" id = "date8" value = "" size =25 >

    I want to be able to access the value in this input once a method in my
    controller is called. How can I do this? params[date8] does not work
    which makes sense since it isnt a ruby textfield. Anyone have any ideas?
    Thanks

    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com (mailto:rubyonrails-talk+unsubscribe@googlegroups.com).
    To post to this group, send email to rubyonrails-talk@googlegroups.com (mailto:rubyonrails-talk@googlegroups.com).
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ronald Zhang at Apr 19, 2013 at 3:22 pm
    Thanks for the reply! I currently have a _form.html.erb file which
    contains all the javascript/html. When I do params[:date8], I see that
    there isn't anything in there. Just an empty string even though
    something was typed into it.

    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Yong Gu at Apr 19, 2013 at 3:33 pm
    check the logs to find out whether other params were passed to the controller or not. Is the input in inside the form? How do you use javascript on that input field?

    --
    Yong Gu
    Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

    On Friday, April 19, 2013 at 11:22 PM, Ronald Zhang wrote:

    Thanks for the reply! I currently have a _form.html.erb file which
    contains all the javascript/html. When I do params[:date8], I see that
    there isn't anything in there. Just an empty string even though
    something was typed into it.

    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com (mailto:rubyonrails-talk+unsubscribe@googlegroups.com).
    To post to this group, send email to rubyonrails-talk@googlegroups.com (mailto:rubyonrails-talk@googlegroups.com).
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ronald Zhang at Apr 19, 2013 at 3:50 pm
    Currently the javascript contains functions for a calendar app so users
    do not have to insert the date manually

    Here is some of the HTMl
    <div>
    <form name = "calendar1">
    <input type = "text" name = "date1" id = "date1" value = "" size =25
    readonly style = "border:0px;">
    <A HREF = "#" onclick =
    "cal.select(document.forms['calendar1'].date1,'anchor1','MM/dd/yyyy');return
    false;" NAME = "anchor1" ID = "anchor1">select date</A>
    </form>
    </div>

    The calendar app works fine, when I test it everything gets inserted
    correctly into the entry field/input. Its trying to get the controller
    to recognize the value of the input. Here is my controller.
    def create
    con = Mysql.new 'xx.xx.x.x','xxxx','xxxx', 'worksheet'
    date1 = params[:date1]
    rs = con.query 'INSERT INTO test VALUES ("'+date1.to_s+'")'
    end
    I know the method is called and everything is linked because the
    database has new entries in it. However, I only see an empty string with
    nothing in it.

    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ronald Zhang at Apr 19, 2013 at 4:16 pm
    Is it possible to pass in the value of date1 into the method when the
    button is pressed? That way I wont have to find a way to reference
    everything in the controller. If so I can I change my button_to to
    reflect that?

    <div>
    <%= button_to "Create", action:"create"%>
    </div>

    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Yong Gu at Apr 19, 2013 at 4:30 pm
    Please not.

    You can either append the value to the url or put the value inside the form.

    You can check whether the date1 was posted to the server. Use web inspector to see the posted data. If the date1 was not even included in the posted data, then you need to check your html and javascript. Or if the date1 was included but it is blank, then you need to figure out why it is blank.

    --
    Yong Gu
    Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

    On Saturday, April 20, 2013 at 12:16 AM, Ronald Zhang wrote:

    Is it possible to pass in the value of date1 into the method when the
    button is pressed? That way I wont have to find a way to reference
    everything in the controller. If so I can I change my button_to to
    reflect that?

    <div>
    <%= button_to "Create", action:"create"%>
    </div>

    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com (mailto:rubyonrails-talk+unsubscribe@googlegroups.com).
    To post to this group, send email to rubyonrails-talk@googlegroups.com (mailto:rubyonrails-talk@googlegroups.com).
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Tamouse at Apr 19, 2013 at 10:51 pm

    On Fri, Apr 19, 2013 at 10:50 AM, Ronald Zhang wrote:
    Currently the javascript contains functions for a calendar app so users
    do not have to insert the date manually

    Here is some of the HTMl
    <div>
    <form name = "calendar1">
    <input type = "text" name = "date1" id = "date1" value = "" size =25
    readonly style = "border:0px;">
    <A HREF = "#" onclick =
    "cal.select(document.forms['calendar1'].date1,'anchor1','MM/dd/yyyy');return
    false;" NAME = "anchor1" ID = "anchor1">select date</A>
    </form>
    </div>

    The calendar app works fine, when I test it everything gets inserted
    correctly into the entry field/input. Its trying to get the controller
    to recognize the value of the input. Here is my controller.
    def create
    con = Mysql.new 'xx.xx.x.x','xxxx','xxxx', 'worksheet'
    date1 = params[:date1]
    rs = con.query 'INSERT INTO test VALUES ("'+date1.to_s+'")'
    end
    I know the method is called and everything is linked because the
    database has new entries in it. However, I only see an empty string with
    nothing in it.
    Install the ruby debugger. Then insert the debugger to start at this point:

    def create
    con = Mysql.new 'xx.xx.x.x','xxxx','xxxx', 'worksheet'

    debugger

    date1 = params[:date1]
    rs = con.query 'INSERT INTO test VALUES ("'+date1.to_s+'")'
    end

    Then, when the debugger starts up, check to see what params contains:
    eval params.inspect
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedApr 19, '13 at 3:04p
activeApr 19, '13 at 10:51p
posts8
users3
websiterubyonrails.org
irc#RubyOnRails

3 users in discussion

Ronald Zhang: 4 posts Yong Gu: 3 posts Tamouse: 1 post

People

Translate

site design / logo © 2021 Grokbase