简体   繁体   English

如何在Ruby on Rails中读取表格式的字段值?

[英]How to read the table formated field value in Ruby on Rails?

I am displaying all values in table formated 我以表格格式显示所有值

View: 视图:

<div style="clear:both; padding-top:1px;">&nbsp;</div>
<%if @signals[0]!=nil %>
<h1>Signal</h1>
<div class="floatleft width100">
            <div class="floatleft width100 padtop_15">
                <div>
                    <table cellspacing="1" cellpadding="1" width="300px" border="0" id="mytable">
                        <tr>
                            <th class="title" style="width:20%"><strong>ID</strong></th>
                            <th class="title" style="width:40%"><strong>Signal</strong></th>
                            <th class="title" style="width:20%"><strong>Geo Subnode</strong></th>
                            <th class="title" style="width:20%"><strong>Track Number</strong></th>
                        </tr>
                        <%@signals.each do |signal| %>
                        <tr>
                            <td ><div align="left"><%= signal.ID %></div></td>
                            <td ><div align="left"><%= signal.Name %></div></td>
                            <td ><div align="left"><%= signal.Subnode %></div></td>
                            <td ><div align="left"><%= text_field_tag "sigtrack#{@sigtrk}", "#{signal.Tracknumber}", :size =>"30px",:class=>"inputbox_big2" %></div></td>
                        </tr>
                        <% @sigtrk=@sigtrk+1 %>
                        <%end%> 
                    </table>
                </div>
            </div>
</div>  
<%end%>

Controller: 控制器:

@signals--> I am loading the table values(id,signal,subnode,tracknumber) for displaying all details @signals->我正在加载表值(id,signal,子节点,tracknumber)以显示所有详细信息

Issue: User should be able to change the value and need to save those value with database.... here the issue is how to read the table formated field values? 问题:用户应该能够更改值,并且需要将这些值保存到数据库中。...这里的问题是如何读取表格式的字段值?

Ah, usually this is what forms are for. 嗯,通常这是表格的目的。 Usually you would make a _signal.html.erb partial. 通常,您会将_signal.html.erb设为部分。

In your partial might then have a form fo each of the fields you care about. 然后,您可能会在您的分公司中为您关心的每个字段创建一个表格。

There are plenty of examples of how to do forms online. 关于如何在线执行表格的例子很多。 Here are some great video tutorials with source code on Github 这是一些很棒的视频教程,带有有关Github的源代码

If you want users to be able to change fields in order to store them in the database you need forms . 如果希望用户能够更改字段以将其存储在数据库中,则需要表格 Part 2 of the guide shows how to create a form for a model, use this information and your loop to create a form for each signal you have. 该指南的第2部分展示了如何为模型创建表单,如何使用此信息以及您的循环为每个信号创建表单。

A more advanced way of changing values is to use AJAX calls, you could made editable table fields. 更改值的更高级方法是使用AJAX调用,您可以使表字段可编辑。 This page shows a demonstation of this method, it is a bit out-dated, but it shows the possibilities. 此页面显示了此方法的演示,虽然有些过时,但它显示了可能性。 A lot of AJAX/Rails related information canbe found on SO as well. 在SO上也可以找到很多与AJAX / Rails相关的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM