2012-11-26 2 views
0

편집 버튼을 클릭하는 동안 새 창을 팝업하는 작업이 있습니다. 그러나이 문제에 대한 해결책은 없습니다. 클래스 학생과 세 가지 속성 이름, 나이 및 지점이 있습니다. 스캐 폴딩을 통해 뷰를 만들었습니다. 나에게 할당 된 작업은 편집 버튼을 클릭하는 동안 해당 속성을 편집 할 수있는 팝업 창이 있어야합니다. 어떻게해야합니까? 제발 도와 줘 .JTable처럼 이걸하고 싶다. 이이 학생 클래스의레일 위의 루비 팝업 창

<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 %> 

컨트롤러 내 index.html.erb입니다

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가 routes.rb이

<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> 

입니다

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

답변

2

대신 팝업을 사용하는 대신 Twitter Bootstrap에 포함 된 것과 같은 팝업 모달을 사용 하시겠습니까? Rails는 팝업을 처리하지 않지만 자바 스크립트로 생성 할 수 있습니다. TopUpprototype-window도 있습니다.

+0

jtable처럼하고 싶습니다. 좋은 생각이야? – Niths

+0

자신 만의 시도를하고 또한 질문에 답을 표시하는 것을 고려해야합니다. – sunnyrjuneja

+0

내 대답을 본 것 같아. – Niths

1

팝업을 처리하는 레일이 없습니다. 자바 스크립트 라이브러리 (jqueryui 또는 기타)를 사용하고 해당 라이브러리를 사용하여 팝업을 만들어야합니다. Rails는 라이브러리 메소드에 전달할 팝업을 위해 HTML을 생성하는 방법으로 만 도움이 될 것입니다.

즉, 레일 앱에 요청을 보낼 버튼이 있습니다. 레일 애플 리케이션은 팝업 html과 함께 자바 스크립트를 생성하고 실행을 위해 클라이언트로 다시 보냅니다. 이를 구현하는 정확한 방법은 사용중인 JS 라이브러리에 따라 다르며이 주제에 대한 연구를 수행 할 수 있습니다.

+0

jquery ui를 (를) 사용하는 데 도움을주세요. – Niths

+0

죄송합니다. 앱을 구현할 수 없습니다. 이 주제에 대해 조사를해야 할 것입니다. SO와 웹에 관한 비슷한 질문이 많이 있습니다. – buftlica

+0

jtable처럼하고 싶습니다. 좋은 생각이야? – Niths