如何制作ajax可编辑单元格?

时间:2011-12-29 11:20:14

标签: ajax ruby-on-rails-3.1

我有这个index.html.erb文件:

   <h3>Pažymiai</h3><br />
    Nuo: <%= @begining_of_week = Date.commercial(2011, 48, 1) %> 
    iki: <%= @end_of_week = Date.commercial(2011, 48, -1) %>
    <table class="macs">
    <tr>
    <th>Vardas, pavardė</th>
    <th>Dalykas</th>
    <% (@begining_of_week..@end_of_week).each do |d| %>
    <th class="calendar"><%= d.day %></th>
    <% end %>
    </tr>
    <% @students.each do |student| %>
        <tr>
            <td class="name" rowspan="<%= @subjects.count %>"><%=link_to(admin_student_path(student)) do %><%= student.name%><br /> <%= student.surname %><% end %></td>
            <% @subjects.each do |subject| %>
            <td class="subject"><%=subject.name%></td>
            <% (@begining_of_week..@end_of_week).each do |d| %>     
            <% @mac = Mac.where(:student_id => student.id, :subject_id => subject.id, :date => d) %>
            <% if @mac.blank? %> 
            <td class="calendar_mac" onclick="location.href='<%= new_admin_mac_path %>'"><center>
            </center>
            <%= link_to 'new_mac', new_admin_mac_path, :remote => true %>
            </td>
            <% else %>
            <% @mac.each do |mac| %>
            <td class="calendar_mac" onclick="location.href='<%= edit_admin_mac_path(mac) %>'"><center> 
            <%= mac.mac%>
            <% end %>
            <% end %>       
            </center></td>
            <% end %>
        </tr>   
    <% end %>
    <% end %>
    </table>

如果单元格为空以写入新值,如果单元格有值使其可编辑,如果单击单元格我需要一个弹出窗口,您可以在其中编辑或向数据库添加新元素。我的表看起来: my table now

1 个答案:

答案 0 :(得分:0)

您可以尝试best in place gem并按照ryanb的示例屏幕投放,这可能会帮助您