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.
rh (Guest)
on 2006-05-08 23: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!
Ben R. (Guest)
on 2006-05-08 23: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 <removed_email_address@domain.invalid> 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
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ben R.
303-947-0446
http://www.benr75.com
Rob M. (Guest)
on 2006-05-08 23:52
(Received via mailing list)
try:
<%= text_field 'post', 'posted_by',
User.find(session[:user_id]).name.capitalize)
%>
Ben R. (Guest)
on 2006-05-08 23:55
(Received via mailing list)
Why not store session[:user_id] in the posted_by field?

~ Ben

On 5/8/06, rh <removed_email_address@domain.invalid> 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
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ben R.
303-947-0446
http://www.benr75.com
rh (Guest)
on 2006-05-09 00:30

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