Forum: Ruby on Rails <%= text_field %> - how to set the value to session name?

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.
1e2dd87a31c5d3e07adc9efa375f4dc4?d=identicon&s=25 rh (Guest)
on 2006-05-08 21:10
I'm trying to automatically fill a "posted_by" text by with whoever is
logged into the session.  How do you set the value attribute using "<%=
text_field ... %>"???

I've tried:

<%= text_field 'post', 'posted_by', 'value' =>
User.find(session[:user_id]).name.capitalize) %>

But I get errors.

If someone can tell me how to do this simple thing, I would really
appreciate it!  Thanks!
D90ef6808433e63203e15a5c2dadb0bb?d=identicon&s=25 Ben Reubenstein (Guest)
on 2006-05-08 21:30
(Received via mailing list)
To make your method work:

 <%= text_field 'post', 'posted_by', :value =>
User.find(session[:user_id]).name.capitalize) %>

On 5/8/06, rh <rheath@ircwv.com> wrote:
>
> If someone can tell me how to do this simple thing, I would really
> appreciate it!  Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ben Reubenstein
303-947-0446
http://www.benr75.com
A4a8fefcbd2cd6d2370609a5e2a3a389?d=identicon&s=25 Rob Merrell (Guest)
on 2006-05-08 21:52
(Received via mailing list)
try:
<%= text_field 'post', 'posted_by',
User.find(session[:user_id]).name.capitalize)
%>
D90ef6808433e63203e15a5c2dadb0bb?d=identicon&s=25 Ben Reubenstein (Guest)
on 2006-05-08 21:55
(Received via mailing list)
Why not store session[:user_id] in the posted_by field?

~ Ben

On 5/8/06, rh <rheath@ircwv.com> wrote:
>
> If someone can tell me how to do this simple thing, I would really
> appreciate it!  Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ben Reubenstein
303-947-0446
http://www.benr75.com
1e2dd87a31c5d3e07adc9efa375f4dc4?d=identicon&s=25 rh (Guest)
on 2006-05-08 22:30

Thanks everyone, it works now.
This topic is locked and can not be replied to.