2016-08-09 52 views
0

我是非常新的rails。我想要做的是如果我想要添加和刪除數據而不刷新頁面。如何添加和刪除,而不使用javascript刷新頁面中的頁面

我已經使用remote => true它正在工作。但是它沒有正確存儲的數據一旦我刷新頁面數據就會顯示。告訴我如何添加數據而不刷新頁面。

Controller.rb

def attribute_creation 
    if $classification_id==nil 
     $classification_id=Classification.last.id 
    end 
    @field_name=[] 
    @field_type=[] 
    field_id=FieldProcess.where(:tree_status=>0).where(:classification_id=>$classification_id).pluck(:field_id) 
    field_id.map do |field| 
    @field_name << FieldMaster.where(:id=>field).to_a 
    @field_type << FieldProcess.where(:field_id=>field).to_a  
    end 
    @field=FieldMaster.new 
    @[email protected]_name.flatten! 
    @[email protected]_type.flatten! 
end 

Attribute_creation.html.erb

<table> 
    <thead> 
    <tr> 
     <th>Field Name</th> 
     <th>Field Type</th> 
     <th>Remove</th> 
    </tr> 
</thead> 
<%unless @field_name1.nil?%> 
    <%@field_name1.each do |field|%> 
    <tr> 
     <td><%= field.field_name%></td> 
     <td><%= FieldProcess.where(:field_id=>field.id).to_a[0].field_type %></td> 
     <td><%= link_to '<i class="fa fa-trash" aria-hidden="true"></i>'.html_safe, images_destroy_field_path(field.id), data: { confirm: 'Are you sure?' }%></td> 
    </tr> 
    <%end%> 
<%end%> 
<%= form_for FieldMaster.new, :remote => true,:url=>{:controller=>"images", :action=>"create_attribute",remote: true} do|m|%> 
    <tr> 
    <td> <%= m.select "id",options_from_collection_for_select(FieldMaster.order("field_name ASC"), "id", "field_name"),{:include_blank=>"Select Option"},:class=>"form-control",:required=>"true"%></td> 
    <td><%= m.select :field_type, ['Text', 'Date', 'Dropdown'], {:include_blank=>"select Option"},:class=>"form-control",:id=>"smcCompny" %></td> 
    <td><%= m.submit "Add",:class=>"btn btn-primary"%></td> 
    </tr> 
<%end%> 

+0

請分享你的控制器代碼,以及看你嘗試過什麼。乾杯! –

回答