ruby on rails

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:
blog_ruby_11

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
blog_ruby_21
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%>

blog_ruby_31
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

Leave a Reply