##Problem
I want to use the same view partial to render the text fields and checkboxes for the new, edit, and show user pages. The fields and checkboxes need to be enabled on the new and edit pages and disabled on the show page. To make that happen, I want to pass the user object and an enabled/disabled boolean to the partial when it's time to render the elements. I found an answer at the
Rails Forum website
Show archive.org snapshot
and, after some trial and error was able to make it work.
##Solution
Create a view partial to render the fields and checkboxes\
Example: ../ezdcapp/app/views/users/_user_field.html.erb
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :user_name %>
<%= f.text_field :user_name, { disabled: disable_element } %>
<%= f.label :first_name %>
<%= f.text_field :first_name, { disabled: disable_element } %>
<%= f.label :last_name %>
<%= f.text_field :last_name, { disabled: disable_element } %>
<%= f.label :password %>
<%= f.text_field :password, { disabled: disable_element } %>
<br />
<%= f.label :admin_flag, class: 'checkbox inline' do %>
<%= f.check_box :admin_flag, { disabled: disable_element, checked: @user.admin_flag == "Y" } %>
Admin User
<% end %>
<%= f.label :read_only, class: 'checkbox inline' do %>
<%= f.check_box :read_only, { disabled: disable_element, checked: @user.read_only == "Y" } %>
Read Only
<% end %>
<br /><br />
Replace the code for the fields and checkboxes with a render statement\
Example: ../ezdcapp/app/views/users/show.html.erb
<%= form_for(@user) do |f| %>
<%= render(:partial => 'user_fields', :object => @user,
:locals => { :f => f, :disable_element => true }) %>
<% end %>
Setting :disable_element to true will disable the fields and checkboxes on the displayed page. Setting :disable_element to false will enable them.
Let me know if you find any errors on this card or if any part of the explanation is not clear. Thanks.