2012-11-26 39 views
0

我得到一個任務,彈出新窗口,同時點擊編輯按鈕。但我無法得到任何解決方案。我有一個班學生和三個屬性名稱,年齡和分支。我通過腳手架創建了視圖。分配給我的任務是在單擊編輯按鈕時,應該有一個彈出窗口來編輯這些屬性。我該如何做?請help.I想要做這個像jTable。 這是我的index.html.erb在軌道上的紅寶石彈出窗口

<table class="tablelist"> 
    <caption>Listing students</caption> 
    <tr> 
    <th>Name</th> 
    <th>Age</th> 
    <th>Branch</th> 
    <th></th> 

    <th></th> 
    </tr> 
<% @students.each do |student| %> 
    <tr> 
    <td><%= student.name %></td> 
    <td><%= student.age %></td> 
    <td><%= student.branch %></td> 

    <td><%=link_to (image_tag("edit.png", :alt => 'Edit'), edit_student_path(student)) %></td> 
    <td><%= link_to 'Destroy', student, :method => :delete, :data => { :confirm => 'Are you sure?' } %></td> 
    </tr> 
<% end %> 
</table> 

<br /> 

<%= link_to 'New Student', new_student_path %> 

控制器這個學生類是

def list 
    @students = Student.all 
    @jtable = {'Result' => 'OK','Records' => @students.map(&:attributes)} 

    respond_to do |format| 
     format.html # index.html.erb 
     format.json { render :json => @jtable} 
    end 
    end 

index.html.erb是

<html> 
    <head> 
     <%=stylesheet_link_tag "jtable_blue","http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css",:media => "all" %> 
     <%= javascript_include_tag "jquery-1.8.3.min","http://code.jquery.com/ui/1.9.1/jquery-ui.js","jquery.jtable.min"%> 
<script type="text/javascript"> 
    jQuery.noConflict(); 
    jQuery(document).ready(function() { 
     jQuery('#StudentTableContainer').jtable({ 
      title: 'StudentList', 
      actions: { 
       listAction: '/students/list', 
       createAction: '/students/newstudent', 
       updateAction: '/students/edit', 
       deleteAction: '/students/destroy' 
      }, 
      fields: { 
       id: { 
        key: true, 
        create: false, 
        edit: false, 
        list: false 
       }, 
       name: { 
        title: 'name', 
        width: '40%' 
       }, 
       sex: { 
        title: 'sex', 
        width: '20%' 
       }, 
       branch: { 
        title: 'branch', 
        width: '30%' 
       } 

      } 
     }); 

     jQuery('#StudentTableContainer').jtable('load'); 
    }); 
</script> 
</head> 
<body> 

    <div id="StudentTableContainer"> 
    </div> 
</body> 
</html> 

的routes.rb是

match 'students/list' => 'students#list', :as => :list 

回答

2

如何不使用彈出窗口而使用彈出窗口模式,如Twitter Bootstrap中包含的彈出窗口模式? Rails不處理彈出窗口,但可以使用JavaScript生成它們。還有TopUpprototype-window

+0

我想做這個像jtable.Any想法? – Niths

+0

你需要投入自己的嘗試,並考慮將你的一些問題標記爲已回答。 – sunnyrjuneja

+0

我想你已經看到了我的答案。 – Niths

1

沒有rails3處理彈出窗口的方法。你必須使用一個JavaScript庫(jqueryui或其他),並使用該庫創建一個彈出窗口。 Rails只會幫助您爲該彈出窗口生成HTML,並將其傳遞給庫方法。

換句話說,您將有一個按鈕,它將發送請求到rails應用程序。 Rails應用程序將生成JavaScript以及彈出的HTML並將其發送回客戶端執行。實現這個的確切方式取決於你正在使用哪個JS庫,並且你可以對這個主題做一些研究。

+0

請幫我做使用jquery ui – Niths

+0

對不起,我無法實現你的應用程序。你將不得不對這個問題做一些研究。 SO和網上有很多類似的問題。 – buftlica

+0

我想做這個像jtable.Any想法? – Niths