Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable a Text Box in Ruby on Rails?

I have the code:

        <% generate_bullets = Bullet.all %>
        <% generate_bullets.shuffle.first(4).each do |t| %>
        <%= f.text_field, :bullets, :class => 'text_field disabled' %>

I want to disable a text box using embedded ruby, and am unable to do so. If I could receive any help on the situation I'm facing, it would be very greatly appreciated.

After I disable the text box I want to have a button generate four random ID's from the database table "bullets" and print them on the disabled text box in an array format, and utilize those four printed ID's to post them onto a created page. Any help with that would be even better.

like image 831
Evan Avatar asked Jun 29 '12 23:06

Evan


2 Answers

Let me know if I'm reading this right: you're trying to disable the text field from the get-go in the HTML. Is that right?

If so, disabled isn't a class; it's its own attribute.

<%= f.text_field, :bullets, :class => 'text_field', :disabled => true %>
like image 74
Matchu Avatar answered Sep 16 '22 14:09

Matchu


You can also use :readonly => true attribute.

For HAML

= f.text_field :name, :class => "form-control", :readonly => true

For ERB

<%= f.text_field :name, :class => "form-control", :readonly => true %>
like image 24
Azmat Rana Avatar answered Sep 17 '22 14:09

Azmat Rana