我有一个注册表单,它有嵌套的关联/属性,无论你想要什么.
我的层次结构是这样的:
class User < ActiveRecord::Base
acts_as_authentic
belongs_to :user_role, :polymorphic => true
end
class Customer < ActiveRecord::Base
has_one :user, :as => :user_role, :dependent => :destroy
accepts_nested_attributes_for :user, :allow_destroy => true
validates_associated :user
end
class Employee < ActiveRecord::Base
has_one :user, :as => :user_role, :dependent => :destroy
accepts_nested_attributes_for :user, :allow_destroy => true
validates_associated :user
end
Run Code Online (Sandbox Code Playgroud)
我在这些课程中也有一些验证内容.我的问题是,如果我尝试使用空白表单创建和客户(或员工等),我会得到所有的验证错误,加上一些通用的错误,如"用户无效"和"客户无效"如果我迭代错误我得到的东西:
user.login can't be blank
User is invalid
customer.whatever is blah blah blah...etc
customer.some_other_error etc etc
Run Code Online (Sandbox Code Playgroud)
由于嵌套用户模型中至少有一个无效字段,因此会在错误列表中添加额外的"X无效"消息.这让我的客户感到困惑,所以我想知道是否有一个快速的方法来做到这一点,而不是自己提交错误.
我需要显示以不同货币呈现的用户数量.eq:
Your balance: $ 100 000.00
€ 70 000.00
3 000 000,00 ???.
Run Code Online (Sandbox Code Playgroud)
所以我需要使用number_to_currency三次不同的语言环境(en,eu,ru).做正确的方法是什么?
首先,看起来DateTime格式变量似乎没有在任何地方记录,因此对于任何可以在rubydocs中向我展示的人来说都是+1 .其次,在查看Date.strftime功能代码时,我没有看到任何可以让我做类似的事情:
Thursday, September 9th 2010
有谁知道这是否可能?
当我thin像这样加载:
thin start -e production
Run Code Online (Sandbox Code Playgroud)
并尝试访问我的一个页面,我在日志输出中得到这个:
cache: [GET /] miss
cache: [GET /assets/main-bd1ef4b153740fb69fd615304b87ad0d.css] miss
cache: [GET /assets/jqModal-8fa734bf4f58524b2799abd73ab7d34f.css] miss
cache: [GET /assets/jquery-544665ba1d5b4f793290421aafed85c9.js] miss
cache: [GET /assets/application-00b97aa2429046c0c43802f07b756b46.js] miss
Run Code Online (Sandbox Code Playgroud)
这些文件存在于我的assets目录下public.
我也运行这个命令:
RALS_ENV=production rake assets:precompile
Run Code Online (Sandbox Code Playgroud)
我试过/public/assets/application.js在浏览器中访问该文件,如下所示:
http://localhost:3000/application.js
Run Code Online (Sandbox Code Playgroud)
这给了我一个404错误(即使该文件存在/public/assets但是当我在服务器处于开发模式时向文件发出请求时可以读取该文件.
有人有主意吗?
我看过很多过时的播客,提到摩卡作为我想要安装的宝石,因为它比rspec更好地模拟.我有一种感觉,rspec开发人员已经抓住了这一点,并从那时起改进了他们的模拟.但是,在默认spec_helper.rb文件中,我看到一些注释掉的代码存根,用于三个模拟框架
mochaflexmockrr向所有能够给我一个合适答案的人提供至少一个这样的框架与rspec自己的模拟框架的利弊.
我会接受一个答案,如果你可以给我一个分解所有三个 rpsec
我不是在问这个因为我需要一个工作场所.我有一个工作正常,但我想知道为什么它没有.这是javascript(或JQuery,因为我使用的是JQuery .keypress处理程序)中的错误,还是有一个特定的原因,为什么会这样?
提前致谢.
我最近更新rubocop了我正在研究的 gem。当我使用 VSCode 在项目中打开一个 ruby 文件时,我收到以下警告:
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file:
- Lint/RaiseException (0.81)
- Lint/StructNewOverride (0.81)
- Style/HashEachMethods (0.80)
- Style/HashTransformKeys (0.80)
- Style/HashTransformValues (0.80)
For more information: https://docs.rubocop.org/en/latest/versioning/
Run Code Online (Sandbox Code Playgroud)
这是我的.rubocop.yml文件:
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file:
- Lint/RaiseException (0.81)
- …Run Code Online (Sandbox Code Playgroud) 我使用的是 ubuntu 9.10,我使用包管理器安装了 java 和 tomcat。当我去运行 startup.sh 时,它首先抱怨 catalina.out 不存在且不可写。我解决了这个问题,它没有抱怨(为什么不包含在安装中??)现在它抱怨当我关闭服务器时 server.xml 不在那里。这是我从命令行的输出:
user@desktop:/usr/share/tomcat6$ ./bin/startup.sh
Using CATALINA_BASE: /usr/share/tomcat6
Using CATALINA_HOME: /usr/share/tomcat6
Using CATALINA_TMPDIR: /usr/share/tomcat6/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun-1.6.0.15
user@desktop:/usr/share/tomcat6$ ./bin/shutdown.sh
Using CATALINA_BASE: /usr/share/tomcat6
Using CATALINA_HOME: /usr/share/tomcat6
Using CATALINA_TMPDIR: /usr/share/tomcat6/temp
Using JRE_HOME: /usr/lib/jvm/java-6-sun-1.6.0.15
Dec 11, 2009 4:42:57 PM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.io.FileNotFoundException: /usr/share/tomcat6/conf/server.xml (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:407)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:337)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
user@desktop:/usr/share/tomcat6$
Run Code Online (Sandbox Code Playgroud)
我真的是 tomcat 的新手,所以这可能是一个愚蠢的问题,但为什么在全新安装的 …
我有一个TimePicker以这种格式返回 24 小时时间的组件:09:00上午 9 点、12:00中午 12 点或20:00晚上 8 点。我的代码中的某些内容需要Date(JSDate),因此我只想获取当前日期/时间,但应用具有事件的组件DateTime.now()中的小时和分钟。我可以像这样处理该事件:TimePickeronClick
// TimePickerValue can either be a string or JSDate
// but the TimePicker is always returning a string
const handleTimeChange = (time:TimePickerValue) => {
// this outputs a time in 24-hour format
console.log("handleTimeChange: ", time)
// I want to set the state of the parent component
// this needs to be in JSDate format so this doesn't …Run Code Online (Sandbox Code Playgroud) ruby ×4
javascript ×2
currency ×1
frameworks ×1
gnu ×1
gpl ×1
keypress ×1
licensing ×1
luxon ×1
mocking ×1
onkeypress ×1
reactjs ×1
rspec ×1
rspec-mocks ×1
rubocop ×1
server.xml ×1
thin ×1
tomcat6 ×1
typescript ×1
ubuntu-9.10 ×1
validation ×1