我想允许用户通过excel电子表格界面添加和编辑数据,并让数据库镜像这些电子表格,或每天自动更新。用户将不被允许编辑电子表格的结构,只是简单地添加或编辑现有行。有没有什么gem允许这种类型的功能?
发布于 2015-03-09 12:34:13
我没有提到Excel,因为我认为这是不可能的,更不用说长期的实践了。
在您的Rails应用程序中创建表。可以使用由scaffold命令创建的标准视图。
然后,通过将best_in_place gem添加到gem文件来安装gem
gem 'best_in_place'在application.js文件中,将best_in_place和jquery.purr添加到文件中的jquery之后:
//= require jquery
//= require jquery.purr
//= require best_in_place为表的控制器创建一个咖啡脚本文件(如果是脚手架,则已经有一个)。在我的示例中,我将其命名为my_tables:
my_tables.js.coffee:
jQuery ->
$('.best_in_place').best_in_place()这就是设置的内容,现在只需修改您的表以使用best_in_place类:
<h1>Listing my_tables</h1>
<table>
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
<th>Col4</th>
<th>Col5</th>
</tr>
</thead>
<tbody>
<% @my_tables.each do |my_table| %>
<tr>
<td><%= best_in_place my_table, :col1 %></td>
<td><%= best_in_place my_table, :col2 %></td>
<td><%= best_in_place my_table, :col3 %></td>
<td><%= best_in_place my_table, :col4 %></td>
<td><%= best_in_place my_table, :col5 %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New My table', new_my_table_path %> 唯一的区别是在单个细胞上。而不是标准:
<td><%= my_table.col1 %></td>我们使用best_in_place方法并向其传递对象和列名符号,而不是点方法:
<td><%= best_in_place my_table, :col1 %></td>现在,如果刷新视图,您将看到与往常一样的表。但是点击任何单元格,它就会变成可编辑的。更改该值并按ENTER键。新值保持不变。重新加载页面,您将看到它仍然具有您为其提供的新值。
https://stackoverflow.com/questions/28933479
复制相似问题