小编roc*_*ock的帖子

如何在ruby on rails的数据表中添加多选?

jquery-datatables-rails在我的应用程序中使用gem。我想在我的应用程序中添加功能多选。在多选时,我想projectdirector在提交时立即设置表格状态。为了实现这个目标,我需要做哪些改变?

project_sitetable 与project_directortable有太多关联。

脚本.js

$( document ).on('turbolinks:load', function(){
      // DataTable feature
      $('#project-director-table').dataTable({
      "order": []
  });
 });

Run Code Online (Sandbox Code Playgroud)

index.html.erb

<div class="table-scroll director-form">
  <table id="project-director-table">
    <thead>
      <tr>
        <th>Uploaded By</th>
        <th>User Email </th>
 
        <th></th>
      </tr>
    </thead>

    <tbody>
      <% @project_sites.where(submission_status: true).order("created_at desc").each do |project_site| %>
        <% project_site.project_managers.each do |project_manager| %>
          <% if project_manager.status == true %>

          <tr>
            <td><%= project_site.user.name %></td>
            <td><%= project_site.user.email %></td>

            <td><%= link_to "Marked Attendance", project_site_attendances_path(project_site) %></td>



            <% if project_site.project_directors.empty? %>
              <td class="pending fi-eye"><%= " Pending" …
Run Code Online (Sandbox Code Playgroud)

datatable ruby-on-rails ruby-on-rails-5

6
推荐指数
1
解决办法
286
查看次数

如何在表单collection_select rails中将多个id作为数组传递?

project具有 one_to_many 关联,stages并且financial
stage具有 one_to_many 关联task
task具有 one_to_many 关联sub_task

Financial#form视图中,我试图传递idcollection_select作为组合 id 的数组,例如(例如:阶段的 id,父阶段的 id。任务的 id,stage.id 的任务的 id。sub_task 的 id。 sub_task)

同样下拉首先访问所有阶段,然后在当前场景中的任务是我如何像第一阶段一样打开下拉,然后是它们对应的所有任务,然后是所有 sub_tasks?

在此处输入图片说明

代码如何识别哪个值来自哪个表,因为下拉来自基于引用的多个表

form.html.erb(财务)

<div class="field column large-8">
  <br>
  <%= form.label :acitivity_Select %>
  <%= form.collection_select :cost_head, @project.stages.all+ @project.tasks.all+ @project.sub_tasks.all, :id, :task_name, prompt: true %>
</div>
Run Code Online (Sandbox Code Playgroud)

项目文件

  has_many :stages
  has_many :tasks, through: :stages
  has_many :sub_tasks, through: :tasks

Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-5

6
推荐指数
1
解决办法
264
查看次数

PG::DatatypeMismatch:错误:列“状态”无法自动转换为整数类型

我在开发中使用了 sqlite3,但在 PostgreSQL 迁移时遇到错误

在数据库的sqlite迁移中没有发现这样的错误。

错误日志

PG::DatatypeMismatch: ERROR:  column "status" cannot be cast automatically to type integer

HINT:  You might need to specify "USING status::integer".
/home/abc/abc/db/migrate/20200211044313_change_status_type_in_stages.rb:3:in `change'

Run Code Online (Sandbox Code Playgroud)

20200113224031_create_stages.rb

class CreateStages < ActiveRecord::Migration[5.2]
  def change
    create_table :stages do |t|
      t.string :stage
      t.boolean :status

      t.timestamps
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

db/20200211044313_change_status_type_in_stages.rb

  def change
    change_column :stages, :status, :integer
  end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

4
推荐指数
1
解决办法
6484
查看次数

标签 统计

ruby-on-rails ×3

ruby-on-rails-5 ×2

datatable ×1