随着最近升级到Rails 4,使用类似下面的代码更新属性不起作用,我收到一个ActiveModel::ForbiddenAttributes错误:
@user.update_attributes(params[:user], :as => :admin)
Run Code Online (Sandbox Code Playgroud)
用户在模型中具有以下attr_accessible行:
attr_accessible :role_ids, :as =>admin
# or any attribute other than :role_ids contained within :user
Run Code Online (Sandbox Code Playgroud)
你如何在Rails 4中完成同样的任务?
ruby-on-rails attr-accessible activemodel strong-parameters ruby-on-rails-4
我有一个看起来像这样的验证:
class Book < ActiveRecord::Base
belongs_to :author
validates :name, uniqueness: { scope: :author_id }
end
Run Code Online (Sandbox Code Playgroud)
问题是我想允许作者id为nil的重复名称.有没有办法使用validates方法(而不是自定义验证)?
假设我有一个ActiveAdmin模型,有两个范围,如下所示:
ActiveAdmin.register Book do
scope :all, default: true
scope :smith #all books by author 'smith'
index do
column :title
column :published_year
column :author
end
end
Run Code Online (Sandbox Code Playgroud)
当用户选择'smith'范围时,我不希望/需要'author'列.
那么有没有办法访问当前范围,只显示其中一个范围内的作者列?我想在这个例子中我可以使用自定义视图并检查数据的实际内容,但我希望有一种更简单,更好的方法.
我正在使用 jest + 酶设置进行测试。如果定义了窗口,我有有条件地呈现某些东西的函数。
在我的测试套件中,当未定义窗口时,我试图达到第二种情况,但我不能强制它。
it('当窗口未定义时产生一些东西', () => {
窗口 = 未定义;
期望(myFunction()).toEqual(thisWhatIWantOnUndefinedWinow);
});
但即使我强制窗口未定义,它也不会达到预期的情况,窗口始终是窗口(jsdom?)
是我的笑话设置有问题还是我应该以另一种方式处理?
我的ActiveAdmin注册模型具有"活动"布尔字段.我想要包含一个批处理操作来一次"激活"多个记录.
我想按照以下说明操作:
http://activeadmin.info/docs/9-batch-actions.html
做一个自定义批处理操作,我有两个问题.
我有这个:
ActiveAdmin.register Venue do
batch_action :deactivate do |selection|
Venue.find(selection).each do |v|
v.active = false
end
end
end
Run Code Online (Sandbox Code Playgroud)
当我尝试激活某些东西时,我得到一个模板未找到错误.它正在寻找"batch_action"模板.我没有在该文档中看到有关需要添加模板的任何内容.如果我添加一个带有该名称的模板,则错误消失并显示模板......这当然不是我想要的.我希望它只是重新显示索引.
在任何一种情况下(有或没有模板),模型都不会更新.我可以在日志中看到它只是选择所选记录而不执行任何其他操作.
我试着通过以下教程来实现这个目的:
和轨道广播
http://railscasts.com/episodes/205-unobtrusive-javascript
..在这两种情况下,我都有同样的问题.控制器没有渲染.js模板(它回退到.html),因为请求标头没有像它应该的那样请求javascript.
我正在使用来自github和jquery 1.4.4的jquery ujs
"data-remote = true"属性正在提供给它应该是的形式.但由于某种原因,这不是修改请求.
如果我切换到prototype.js它可以工作(使用rails中的默认prototype.js和rails.js).
我正在使用rails 3.0.0
任何建议赞赏.
我有以下内容
在/ app/models中:
class Area < ActiveRecord::Base
has_many :locations
end
class Location < ActiveRecord::Base
belongs_to :area
end
Run Code Online (Sandbox Code Playgroud)
在/app/test/factories/areas.rb中
FactoryGirl.define do
factory :area do
name 'Greater Chicago Area'
short_name 'Chicago'
latitude 42
longitude -88
end
factory :losangeles, class: Area do
name 'Los_Angeles Area'
short_name 'Los Angeles'
latitude 50
longitude 90
end
end
Run Code Online (Sandbox Code Playgroud)
在/app/test/factories/locations.rb中
FactoryGirl.define do
factory :location do
name "Oak Lawn"
latitude 34
longitude 35
association :area
end
factory :malibu, class: Location do
name "Malibu"
latitude 60
longitude -40
association :losangeles …Run Code Online (Sandbox Code Playgroud) 我试图在没有标准对话框的情况下实现语音识别(它在对话框中工作正常).
我尝试开始收听时收到错误代码9.
我的设备是LG G Stylo(运行Android 6.0).
表现:
<manifest package="example.com.myapplication"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application
.....
Run Code Online (Sandbox Code Playgroud)
(也尝试添加INTERNET权限,即使这不应该是必要的,因为离线识别应该正常工作)
的build.gradle:
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "example.com.appname"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
Run Code Online (Sandbox Code Playgroud)
语音识别码:
private SpeechRecognizer speechRecognizer;
protected void onCreate(Bundle savedInstanceState) {
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
speechRecognizer.setRecognitionListener(new speech_listener());
Intent intent = new intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
getApplication().getPackageName());
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.ENGLISH);
speechRecognizer.startListening(intent);
Run Code Online (Sandbox Code Playgroud)
监听器(内部)类:
class speech_listener implements RecognitionListener
{
public void onReadyForSpeech(Bundle params){}
public void onBeginningOfSpeech(){}
public void onRmsChanged(float rmsdB){}
public void …Run Code Online (Sandbox Code Playgroud) 我每次运行咖啡命令时都会看到弃用通知.通知是这样的:
path.exists is deprecated. It is now called `fs.exists`.
Run Code Online (Sandbox Code Playgroud)
我知道这种情况正在发生,因为node.js不推荐使用path.exists.看到
https://github.com/joyent/node/pull/2587
我认为会有很多关于此的信息,但我能看到的是一些间接的参考,涉及一个更严重的问题,说它不会被"修复":
https://github.com/jashkenas/coffee-script/issues/2113
我是唯一一个遇到这个问题的人吗?有没有人建议如何让它消失?
我正在尝试在CentOS Linux上设置gitlist(如果重要的话,请使用gitolite - 我放宽了对gitolite管理的repo目录的权限).
我从今天开始从gitlist.org中提取了0.3版tarball.
我的config.ini看起来像这样:
client = '/usr/bin/git' ; Your git executable path
repositories = '/home/gitolite/repositories/' ; Path to your repositories
[app]
debug = true
; I don't know if baseurl is still needed..seems like my results are the same either way
baseurl = 'http://sub.example.com.com/gitlist' ; Base URL of the application
Run Code Online (Sandbox Code Playgroud)
httpd.conf中的虚拟主机指令:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName sub.example.com
<Directory "/var/www/html">
AllowOverride All
Options -Indexes
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
htaccess的:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /var/www/html/gitlist/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule …Run Code Online (Sandbox Code Playgroud) activeadmin ×2
activemodel ×1
activerecord ×1
ajax ×1
android ×1
coffeescript ×1
deprecated ×1
enzyme ×1
factory-bot ×1
git ×1
gitolite ×1
jestjs ×1
jquery ×1
node.js ×1
reactjs ×1
testing ×1