小编Dan*_*ier的帖子

Rails简单形式给出了InvalidAuthenticityToken错误

我有一个这样的简单形式:

<form name="serachForm" method="post" action="/home/search">   
  <input type="text" name="searchText" size="15" value="">
  <input class="image" name="searchsubmit" value="Busca" src="/images/btn_go_search.gif" align="top" border="0" height="17" type="image" width="29">
</form>
Run Code Online (Sandbox Code Playgroud)

和这种方法的控制器:

  def busca
    puts params[:searchText]
  end
Run Code Online (Sandbox Code Playgroud)

当我单击表单中的图像按钮时,我得到一个ActionController :: InvalidAuthenticityToken.这是完整的StackTrace:

/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/request_forgery_protection.rb:86:in verify_authenticity_token' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:178:in send'/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support /callbacks.rb:178:in evaluate_method' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/callbacks.rb:166:in 调用'/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:225:in call' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:629:in run_before_filters'/ Library /Ruby/Gems/1.8 / gems /actionpack-2.2.2/lib/action_controller/filters.rb:615:in call_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:610:in perform_action_without_benchmark'/ Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller / benchmarking.rb:68:in perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:in perform_action_without_caching' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:inperform_action'/ Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in cache' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:in cache'/ Library/Ruby/Gems/1.8/gems/actionpack -2.2 .2/lib/action_controller/caching/sql_cache.rb:12:in perform_action' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in send process_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in '/Library /Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in process_without_session_management_support'/ Library /Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session_management.rb:134:in process' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in process'/ Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/webrick_server.rb …

forms ruby-on-rails token

6
推荐指数
3
解决办法
7046
查看次数

如何使用RubyOnRails访问Interbase(.IB)数据库?

我在Interbase中有一个数据库,我想使用ActiveRecord直接从我的Rails应用程序访问它.我该怎么做?

database interbase ruby-on-rails

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

ActiveRecord错误消息:字段的翻译

我已经使用http://guides.rubyonrails.org/i18n.html中指定的指令 来翻译我的模型的字段,但标签没有翻译.我做错了什么.

我有一个User该领域的模型,name我想把它翻译成巴西葡萄牙语(pt_br),所以我得到了我的pt_br.yml:

pt_br:
    errors: "Erro!"
    activerecord:
        models:
            user: "Usuário"
        attributes:
            name: "Nome"
            address: "Endereço"
        errors:
            template:
                body: "Por favor, corrija os campos assinalados"
                header: "Dados inválidos"
            messages:
                blank: "é obrigatório"
                taken: "já existe"
                too_short: "incompleto"
Run Code Online (Sandbox Code Playgroud)

当我到达带有表单的页面时:

<% form_for(@usuario) do |f| %>
<%= f.error_messages %>
<%= f.label :name %>
<%= f.text_field :name %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

我将这个字段标记为"名称",而不是像我希望的那样"Nome".我也有

config.i18n.default_locale = :pt_br 
Run Code Online (Sandbox Code Playgroud)

在我的环境中.rb

缺什么?

forms activerecord ruby-on-rails internationalization

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

Rails ActiveRecord:删除具有外键约束的依赖实体时出现严重错误

我在 Rails 应用程序中有几个带有外键约束的表。例如,每个订单都属于一个客户。订单表中有一个costumer_id列。

当我删除已下订单的客户时,由于数据库限制,MySQL 返回错误:

Mysql::Error: 无法删除或更新父行:外键约束失败 ( orders, CONSTRAINT orders_ibfk_2FOREIGN KEY ( customer_id) REFERENCES customers ( id))

屏幕上弹出丑陋的错误,所有堆栈跟踪和那些 ActiveRecord::StatementInvalid 在 DevicesController#destroy ...

我想知道是否有一种优雅的方法来处理这些约束错误,比如“你可以删除这个对象,因为它与 X 相关联”

我怎么能做到?

error-handling activerecord ruby-on-rails

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

echoprint codegen for Java/Android

有没有办法在Android上运行echoprint-codegen或者是否有Java实现?

Eithop上的Echoprint codegen:https://github.com/echonest/echoprint-codegen

有一个C++实现吗?我只是无法弄清楚如何将它移植到Java,以便我可以在Android设备上运行它,假设Android 2.2及以上.

c java android audio-fingerprinting echoprint

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

Echoprint iOS缺失框架

有没有人下载过EchoPrint的iOS版演示版?这是一个音频指纹识别开源软件.

我刚刚下载了它,但似乎缺少框架......任何可以获得功能版本的地方?

audio-fingerprinting ios echoprint

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

如何在Struts 1中使用Tiles2

是否可以在Struts 1中使用Tiles2?

我已按照迁移指南http://tiles.apache.org/migration/index.html上的说明进行操作

但是当我尝试访问我的操作时,我收到此错误:

org.apache.tiles.template.NoSuchAttributeException: Attribute 'body' not found.
Run Code Online (Sandbox Code Playgroud)

我有struts-config.xml:

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"
    maxFileSize="10M" tempDir="/tmp" />

<plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
</plug-in>
Run Code Online (Sandbox Code Playgroud)

和tiles-defs.xml

    <definition name="mainTemplate" template="/common/templates/mainTemplate.jsp" />
    <definition name="index" extends="mainTemplate">
        <put-attribute name="body" type="string" value="/views/index/index.jsp"  />
    </definition>
Run Code Online (Sandbox Code Playgroud)

java tiles tiles2 struts-1

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

如何轻松地将本地文件发送到 Scala 中的 Google Cloud Storage

我需要使用 Scala 语言将本地文件上传到 Google Cloud Storage。最简单的方法是什么?此文件也需要稍后公开下载。

java storage scala google-cloud-storage

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

Aerospike 中批处理请求的低性能

我有一个应用程序可以执行很多 batchGets(主要是大约 2000 个键)。这是我使用的代码:

AerospikeClient aerospike = new AerospikeClient("10.0.240.2", port)

public byte[][] getBatch(byte[][] keys) {
    Key[] aeroKeys = new Key[keys.length];
    for (int i = 0; i < keys.length; i++) {
        aeroKeys[i] = new Key(NAMESPACE, setName, keys[i]);
    }
    Record[] records = aerospike.get(batchPolicy, aeroKeys);
    byte[][] response = new byte[keys.length][];

    for (int i = 0; i < keys.length; i++) {
        if (records[i] != null) {
            response[i] = (byte[]) records[i].getValue(DEFAULT_BIN_NAME);
        }
    }
    return response;
}
Run Code Online (Sandbox Code Playgroud)

当我有一个请求时,此代码可以完美且快速地运行。但是当我运行多个并行线程执行 batchGets 时,它非常慢(退化与线程数成线性关系,例如 4 个线程 = 4 倍慢,8 个线程 …

java multithreading batch-processing aerospike

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

Guard rspec-rails:仅运行模型规格

我们正在使用 Guard gem 在 Rails 5 应用程序上自动运行规范。如何将其配置为仅运行模型规格?我们的配置是:

guard :rspec, cmd: 'spring rspec -p', parallel: true, failed_mode: :focus do
Run Code Online (Sandbox Code Playgroud)

我们尝试将其更改为

guard :rspec, cmd: 'spring rspec ./spec/models/ -p', parallel: true, failed_mode: :focus do
Run Code Online (Sandbox Code Playgroud)

但它仍然运行所有测试。

ruby rspec ruby-on-rails guard

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