2012-07-31 4 views
-2

도와주세요 !!어떻게이 논리를 구성 할 수 있습니까

편집 가능한 데이터 테이블을 만들고 싶습니다. 테이블의 맨 위에는 자바 스크립트로 테이블에 행을 추가하는 "추가"버튼이 있습니다. 그리고 각 행에 butons (링크) "Save"와 "Delete"가 있어야합니다.

어떻게 게시물 요청을 서버로 보낼 수 있습니까? application.js에서 내 지루함 죄송합니다

..

나는이

function AddElementsToPage(elements) { 
/*elements - is array with name elements whose will be add to page*/  
this.add_row_to_data_table = function(obj,attributes,selector_table){ 
    last_row_of_table = selector_table.find('tbody tr').last(); 
    var new_row = "<tr><th scope='row'></th>"; 

    if ($.isEmptyObject(last_row_of_table.html())) 
    { 
     $.each(attributes, function(index, item){ 
      input_tag = "<input id=\""+obj+"_"+item+"\" name=\""+obj+"["+item+"]\" size=\"10\" type=\"text\" />"; 
      new_row = new_row + "<td>"+input_tag+"</td>"; 
     }) 
     alert(new_row); 
     selector_table.append(new_row+"</tr>"); 
    }else 
    { 
     alert("not empty"); 
    } 

} 

내 컨트롤러 액션의 새로운

def new 
@table_row = SchOfWorkInformation.new 
respond_to do |format| 
    format.js do 
    render :action => 'new' 
    end 
end 
end 

내 new.js 같은 기능을

파일이
var obj = new AddElementsToPage(); 

obj.add_row_to_data_table("sch_of_working",["date","hour"], $('.data_table')) 

내 ndex.haml

= link_to content_tag('span', "Add" , :class=>"add"), new_sch_of_work_information_path, :remote => true 
%table{:border=>"1", :class=>"data_table", :style=>"width:450px"} 
    %thead 
     %th{:style=>"width:5%;"} № 
     %th{:style=>"width:10%;"} Date 
     %th{:style=>"width:10%;text-align:center;"} schedule_code 
     %th{:style=>"width:2%;",:class=>"transperent_right_border"} 
     %th{:style=>"width:2%;"} 
    %tbody 
     %tr 
     %th{:scope=>"row"} 
     %[email protected] 
     %[email protected]_code 
     %td{:style=>"text-align:center"}= link_tag "save", sch_of_work_informations, #how can send post request in here 
     %td{:style=>"text-align:center"} 
+4

이것은 매우 일반적인 질문입니다. 몇 가지 코드를 게시하고, 시도한 것을 Google에 보여 주며, 구체적으로 물어보십시오. – Utkanos

+0

Utkanos, 편집 가능한 데이터 테이블을 만들고 싶습니다. 내가 버튼을 클릭하면 테이블 상단에 추가, 그것은 입력 태그와 함께 행을 추가해야합니다. 그리고이 행은 버튼 저장 (또는 링크)과 일치해야합니다. 이제는 어떻게 구성해야할까요? – dilshod

+0

하지만 코드를 게시하지 않았거나 현재 작업하고있는 것을 보여주었습니다. 당신은 효과적으로 전체 솔루션을 요구하고 있습니다. 이것이 SO가 아닌 것입니다. 귀하가 시도한 것을 보여주십시오. 특정 문제에 대한 도움이 필요하면 도움을받을 수 있습니다. – Utkanos

답변

0

나는 이것이 당신이보고있을 것 같은 대답이라고 생각합니다. railscasts http://railscasts.com/episodes/196-nested-model-form-part-1 중첩 된 양식에서 자습서를 따르십시오 그리고 당신을 도울 것입니다. 기본적으로 당신은 행 추가 버튼을 가질 것이고 그것은 자바 스크립트에서 html 행을 추가 할 것입니다. 심지어 행 버튼을 제거 할 수도 있습니다. 이 작업이 완료되면 양식의 저장 버튼을 눌러 모든 변경 작업을 수행 할 수 있습니다.

관련 문제