November 26th, 2009
rails trick:disable and set default value to text field in rails
No Comments », Ruby On Rails, Web Development, by Emperor_bear
Today I’ll talk to little tricks about text_field in ruby on rails. let’s begin…..
When we usually use text_field in ruby on rails we will use like this:
<%= f.label :name%> <%= f.text_field :name %>
so the output will be like this:
![]()
if we want to give the default value for this text field we can do by insert a bit code
<%= f.label :name%> <%= f.text_field :name , :value => 'hello world' %>
now the page will include “hello world” in text field when it’s opened
![]()
then we don’t want any people to edit our “hello world” so
<%= f.label :name%> <%= f.text_field :name , :value => 'hello world', :disabled => true%>
![]()
haha no one can take our “hello world” any more.
but we want to keep “hello world” in our database so we can request a help from hidded field by
<%= f.label :name%> <%= f.text_field :name , :value => 'hello world', :disabled => true%> <%= f.hidden_field :name, :value => 'hello world'%>
that is all.
Thank for today see you next time.
Last 5 posts by Emperor_bear
- Create blog and use Rich Editor in Groovy on Grails (grails-ui plugin) - February 22nd, 2010
- wonder hash in Ruby - November 24th, 2009
- มาเริ่มเขียน Objective-C กับ Xcode ซึโค่ย IDE - October 30th, 2009
- การขึ้นบรรทัดใหม่กับ Random Access File - August 17th, 2009
- Is JRuby GOOD? - August 6th, 2009
