Sterling Rose Design Blog

Using AJAX to Change a User's Role

2 Comments
Tags: Rails AJAX

Scenario: Client wants to display a list of users, and the role each user currently has. The user’s role should be the selected option in a select box of all roles. Administrator should be able to update the user’s role by simply selecting a new role from the select box for that user, without having to reload the page.

Approach: Each row in the user’s list should have an id that uniquely identifies it as being associated with that particular user. Each select box should also have an id field associated with the user. Choosing a new role should trigger the onchange event, which executes the update on the role and displays the new user’s row in place, without reloading the entire user list.

Code:

## app/views/users/index.html.erb

 <table>
   <% @users.each do |u| %>
     <tr id='user_row_<%= "#{u.id}" %>'>
       <td><%= link_...
Read the whole post...

eWeek Covers Rails 2.3 RC 1

0 Comments
Tags: Rails media

Darryl K. Taft of eWeek asked several of us who tweet about Rails what we thought about yesterday’s release of Rails 2.3 Release Candidate 1. Here is the article, along with my own thoughts.


Copyright 2007-2010, Sterling Rose Design. All rights reserved.