Forum: Ruby on Rails Passing form information

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
536253930b065b5a5e8ff9b204c85001?d=identicon&s=25 Sean McGilvray (Guest)
on 2008-11-26 17:05
(Received via mailing list)
Hello everyone I am new to RoR and I was wanting to know how to pass
form information (first_name, last_name, phone_number, and email) to a
session so that I can use them in another form later?

Thank you
4ddf8432a838f716cc499e43131e5e58?d=identicon&s=25 James Englert (Guest)
on 2008-11-26 17:12
(Received via mailing list)
Try

session[:firstname] = firstname;

Hope that helps.

http://www.jim-rants.com/coding-blog/
536253930b065b5a5e8ff9b204c85001?d=identicon&s=25 Sean McGilvray (Guest)
on 2008-11-26 17:15
(Received via mailing list)
Can I go session[:prospect] = params
[:first_name, :last_name, :email, :phone_number]

Will this put them all in one session and allow me to pull them from
that session later?
9cf6e7f81d4339295b86e5fb7d7df49b?d=identicon&s=25 Vishwanath Nayak (nayak)
on 2008-11-26 18:33
(Received via mailing list)
Hi Sean,

By default, you can use the hash either use the whole Hash or value of
one
key at a time to store and retrieve in another Hash
But you can add this to your class to open HashWithIndifferentAccess and
add
"values" method for you

class HashWithIndifferentAccess
  def values(*indices)
    hash = {}
    indices.each {|i| hash[i] = self[i]}
    p hash
    hash
  end
end

#Example
a = {}
a[:a] = 1
a[:b] = 2
a[:c] = 3
a[:d] = 4
a[:e] = 5

b = a.values(:a, :b)#{:a=>1, :b=>2}
Please let me know if you have a doubts using the same

Regards,
NAYAK<nayakk@gmail.com>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-26 19:18
(Received via mailing list)
On Nov 26, 5:32 pm, NAYAK <nay...@gmail.com> wrote:
> Hi Sean,
>
> By default, you can use the hash either use the whole Hash or value of one
> key at a time to store and retrieve in another Hash
> But you can add this to your class to open HashWithIndifferentAccess and add
> "values" method for you

Why add that method when there's already a values_at method that does
exactly that ?

Fred
536253930b065b5a5e8ff9b204c85001?d=identicon&s=25 Sean McGilvray (Guest)
on 2008-11-26 19:21
(Received via mailing list)
How does the values_at method work?


Sean McGilvray & Sarena Byers
Executive Director
Identity Theft Specialist
Pre-Paid Legal Service's, Inc. NYSE:PPD
Phone:  760-486-1019
smcgilvray@prepaidlegal.com
http://www.transferhome.net


On Wed, Nov 26, 2008 at 10:18 AM, Frederick Cheung <
9cf6e7f81d4339295b86e5fb7d7df49b?d=identicon&s=25 Vishwanath Nayak (nayak)
on 2008-11-26 19:27
(Received via mailing list)
Hi,

values_at method does not do the same as it returns a array and hence we
cannot restore the values in a hash for later purposes
BTW values_at can be used as
a.values_at(:a, :b)

Regards,
NAYAK
536253930b065b5a5e8ff9b204c85001?d=identicon&s=25 Sean McGilvray (Guest)
on 2008-11-26 19:28
(Received via mailing list)
Thank you

Sean McGilvray & Sarena Byers
Executive Director
Identity Theft Specialist
Pre-Paid Legal Service's, Inc. NYSE:PPD
Phone:  760-486-1019
smcgilvray@prepaidlegal.com
http://www.transferhome.net
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-26 19:52
(Received via mailing list)
On Nov 26, 6:26 pm, NAYAK <nay...@gmail.com> wrote:
> Hi,
>
> values_at method does not do the same as it returns a array and hence we
> cannot restore the values in a hash for later purposes
> BTW values_at can be used as
> a.values_at(:a, :b)
>

Oops, getting mixed up here. The method I meant was slice (which is a
rails addition). If you do add a method, I wouldn't call it values, as
that would overwrite the usual values method which might cause
problems further down the line.

Fred
This topic is locked and can not be replied to.