小编Chr*_*dla的帖子

你如何使 Rails 多选下拉工作

我正在尝试使用搜索参数对话框制作多选下拉菜单。我可以进行下拉多选,但似乎无法获取/传递结果数据。(编辑/新信息将以斜体显​​示)

我相信问题的根源在于我需要更改控制器中的 permit 部分以反映我正在传递哈希/数组。如果我查看结果记录,我设置为多选的 2 个字段显示为 nil。但是,如果我强制出现错误,rails 显示的参数会显示正确的选择。因此,我认为问题可能出在许可部分。

那看起来像

 *def search_params
      params.require(:search).permit(:document_title,
                                     :summary,
                                     :owner,
                                     :category,
                                     :file_name,
                                     :doc_to_email,
                                     :categories_attributes => [:name])
    end*
Run Code Online (Sandbox Code Playgroud)

我添加了 :categories_attributes => [:name] 以尝试让控制器允许散列,但这不起作用。

选择字段是

 <%= f.select :category[], options_for_select(@categories.sort), {:include_blank => true}, {:multiple => true, :size =>10}  %>
Run Code Online (Sandbox Code Playgroud)

但这给了我

.erb 其中第 41 行提出:

参数数量错误(0 表示 1..2)模板包含的痕迹:app/views/searches/new.html.erb

我以为我必须使用 [] 将类别设置为数组,但显然我遗漏了一些东西。

类别是搜索表中的字符串字段。

ruby-on-rails

5
推荐指数
1
解决办法
1万
查看次数

为什么确认 rails button_to helper 的选项不起作用

我有一个轨道 button_to,我希望它在继续之前显示一个确认对话框。

<%= button_to("Rebuild indexes", action: "rebuild_indexes", data:
{confirm: "Are you sure you want to reset the indexes?" }) %>
Run Code Online (Sandbox Code Playgroud)

操作正在发生,但我没有收到确认框。我读到这个问题可能与javascript有关。我以为我已经启用了。

application.js
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require turbolinks
//= require tinymce-jquery
//= require ckeditor/init
//= require ckeditor/config.js
//= require jquery.are-you-sure
//= require script
//= require script.responsive
//= require_tree .
Run Code Online (Sandbox Code Playgroud)

如果我对按钮进行检查,我会看到

<form class="button_to" method="post" action="/help/rebuild_indexes?data%5Bconfirm%5D=Are+you+sure+you+want+to+reset+the+indexes%3F">
  <input type="submit" value="Rebuild indexes">
  <input type="hidden" name="authenticity_token" value="3mnAMmyHaINiDngjQn87EMmhmetp2VJcX+lwcmbUlhwBfv7V1hpLc9ZY1OF5JAFm9erFJjX+qyDz35/KK41jaA=="> …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

5
推荐指数
2
解决办法
7349
查看次数

link_to 确认不与控制器/操作一起使用

更新 - 我刚刚检查过,但都没有确认是否有效。

我需要确认 link_to。我尝试了数据/确认属性的几种变体,但它绕过了确认对话框。

我的链接是

 <%= link_to 'new bs line', 
   :controller => :bedsheet_lines, 
   :action => :create_new_bedsheet_line,  
   :data => {:confirm => 'Are you sure that you want to export the Bedsheets?'} %> <br>
Run Code Online (Sandbox Code Playgroud)

这不起作用,但常规的 link_to 可以:而且这个也不起作用

  <%= link_to "Export Data as a CSV file ", 
      slitter_bedsheet_export_path(format: "csv"), 
      :data => {:confirm => 'Are you sure that you want to export the Bedsheets?'} %> <br>
Run Code Online (Sandbox Code Playgroud)

如果我进行检查,不会显示确认的链接看起来像

  <a href="/bedsheet_lines/new_bedsheet_line?
   data%5Bconfirm%5D=Are+you+sure+that+you+want+to+export+the+Bedsheets%3F">
  new bs line</a> <br>
Run Code Online (Sandbox Code Playgroud)

而显示确认的链接看起来像Nor dies 这项工作。

  <a data-confirm="Are you …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

3
推荐指数
1
解决办法
2356
查看次数

我不能让ckeditor允许除基本属性以外的任何东西,并且无法关闭/配置高级内容编辑器(rails)

我在rails应用程序上的ruby上运行ckeditor 4.1.4.高级内容编辑器似乎剥离了除基本属性之外的任何东西.

例如,如果我有一个带有'这是一个测试'的单词doc,其中'是一个测试'是粗体,红色和28点并且使用clipview显示查看剪贴板的内容

<body lang=EN-US style='tab-interval:.5in'>
<!--StartFragment-->

<p class=MsoNormal>This <b style='mso-bidi-font-weight:normal'><span
style='font-size:28.0pt;line-height:107%;color:red'>is a test</span></b><o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<!--EndFragment-->
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

它似乎正在拾取颜色,大小和粗体属性.

但是,当我使用ckeditor将其粘贴到文本区域并查看ckeditor中的源代码时,我明白了

<p>This <strong>is a test</strong></p>
Run Code Online (Sandbox Code Playgroud)

除了strong之外的属性已被删除.

我在表格上的身体标签是

  <div class="field">
      <%= f.label :body %><br>
      <%= f.cktext_area :body,  :rows => 80, :cols => 120 %>
    </div>
Run Code Online (Sandbox Code Playgroud)

我已进入C:\ Ruby200\lib\ruby​​\gems\2.0.0\gems\ckeditor-4.1.4\app\assets\javascripts\ckeditor\config.js并添加

config.allowedContent = true;
config.extraAllowedContent = '*(*);*{*}';
config.removeFormatAttributes = '';

CKEDITOR.editorConfig = function( config )
{
  // Define changes to default configuration here. For example:
Run Code Online (Sandbox Code Playgroud)

我尝试在块内添加三个配置行,但是没有用.我读了一个关于在配置块之外添加它们的建议,所以我尝试了.我确实重新启动了服务器,但它仍然删除了其他属性.

这是一个内部网应用程序,鉴于我们的情况,我并不担心内容过滤.我只希望用户能够复制并粘贴所有属性.

------编辑1

我查看了页面的来源并查看

//<![CDATA[
(function() { if (typeof CKEDITOR …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ckeditor

2
推荐指数
1
解决办法
549
查看次数

如何删除活动管理节目中的编辑按钮

我想删除活动管理显示页面上任何记录的编辑按钮,月份和年份等于当前月份和年份的记录除外。

我能够在索引中做到这一点

  if (es.month == Date.today.strftime("%m").to_i) && (es.year == Date.today.strftime("%Y").to_i )
    span link_to 'Edit', "/executive_summaries/#{es.id}/edit"
  end
Run Code Online (Sandbox Code Playgroud)

我的 Executive_summaryies.rb 包括

ActiveAdmin.register Executive::Summary do
  menu :parent => 'Reports'

  config.batch_actions = true

 . . .

  action_item :only => :show do
     link_to_function("#{ActiveAdmin::Iconic.icon(:document_stroke)} Print Executive Summary".html_safe, "javascript:print()")

  end

 . . .

 controller do

 . . . 

    def edit
      @run_js_functions = %w(ExecutiveSummaries.init)
    end

    def show
      @run_js_functions = %w(ExecutiveSummaries.accordion)
    end

    . . . 

end
Run Code Online (Sandbox Code Playgroud)

目前代码的方式是,编辑按钮显示在标题栏中(我相信默认情况下),旁边有一个打印按钮。(来自上面显示的代码)。

如何在显示/查看页面上显示当前月份和年份记录的编辑按钮?

ruby-on-rails ruby-on-rails-3 activeadmin

2
推荐指数
1
解决办法
4395
查看次数

Can Rails能否将shell命令传递给本地机器?

我试图让rails选择文档附件,然后启动附带文档的电子邮件客户端.

我有它在我的开发笔记本电脑上工作.如果我使用适当的参数构建一个字符串并将其传递给system(),那么它将使用附件启动电子邮件客户端.

字符串看起来像

@email_content ="C:\ Program Files(x86)\ IBM\Lotus\Notes \notes.exe""Mailto:?Attach = C:\ Users\cm\RubymineProjects\technical_library\public\images\1\8302_printed.pdf

第一部分调用notes exe,第二部分启动并通过附件发送电子邮件.这在我的笔记本电脑上运行良好

但是,当我将它移动到服务器时,它并没有启动电子邮件客户端.我相信这是因为shell命令试图在服务器上执行,而不是在客户端上执行.

是否可以在客户端计算机上运行shell命令?我试图首先使用Windows,然后使用Mac环境.我尝试将C:\更改为机器名称.ie\chrislaptop\Program Files(x86)\ IBM\Lotus\Notes \notes.exe.但那没用.

shell ruby-on-rails

0
推荐指数
1
解决办法
51
查看次数