published: June 25th, 2008
Rails hint, or at least a reminder for myself
Here is some coding I used to set up two simple forms to edit attributes for a simple Project/Task feature of my new application. For the life of me, I was having a hell of a time figuring out how to default the UI elements to show the current value for the model object.
I finally got it by setting adding the “task.complete” and the “task.assigned_user_id” values of the check_box_tag and select_tag.
Still to do, make the calls to the controllers restful and add in AJAX so it doesn’t refresh the entire page.
<% form_tag (:controller => 'tasks', :action => 'task_completed', :id => task) do %> Complete? <%= check_box_tag :completed, '1', task.complete, :onchange => 'submit()' %> <% end %> <% form_tag (:controller => 'tasks', :action => 'change_assigned_to', :id => task) do %> Assigned to: <%= select_tag (:user_id, options_for_select( @users_select, task.assigned_user_id), :onchange => 'submit()') %> <% end %>
