假设用户模型使用带有strong_parameters的Rails4.
class User < ActiveRecord::Base
has_secure_password
accepts_nested_attributes_for :identity
// rest of code omitted for brevity
end
Run Code Online (Sandbox Code Playgroud)
如果我参考指南我应该能够做到
def user_params
params.require(:user).permit(:email, identity_attributes: [])
end
Run Code Online (Sandbox Code Playgroud)
允许每个identity_attribute的mass_assignment,无论其名称或编号如何.但这是在"未经许可的参数:identity_attributes"中运行的
但是,如果我指定identity_attributes它是有效的
def user_params
params.require(:user).permit(:email, identity_attributes: [:last_name, :first_name])
end
Run Code Online (Sandbox Code Playgroud)
我在Identity中有很多属性,我可以通过User对它们进行mass_assign,而不指定所有属性.
我错过了什么吗?这是一个错误吗?
干杯
我有一个PHP在目录中创建一个mp3文件的JSON数组.PHP的JSON数组输出是:
[{"title":"Kalimba","mp3":"/path/to/mydirectory/Kalimba.mp3"},{"title":"Maid with the Flaxen Hair","mp3":"/path/to/mydirectory/Maid with the Flaxen Hair.mp3"},{"title":"Sleep Away","mp3":"/path/to/mydirectory/Sleep Away.mp3"}]
Run Code Online (Sandbox Code Playgroud)
很好,它似乎是JQuery.jPlayer所期望的.
现在在一个基本的jplayer.js文件中,我有:
$(document).ready(function(){
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [
//I guess my JSON array should come here
// but no idea on how I put it in...
], {
swfPath: "../js",
supplied: "mp3",
wmode: "window"
});
});
Run Code Online (Sandbox Code Playgroud)
我的问题是我不能把我的JSON数组放在它应该的位置(参见js代码中的注释)
任何帮助将非常感谢!原谅我的英语,这不是我的母语,提前谢谢
大家好,对于那些有兴趣的人,我找到了一个解决方案:我的JS文件是:
$(document).ready(function(){
var cssSelector = {
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
};
var playlist = []; // Empty playlist
var options = {
swfPath: "./js",
supplied: "mp3" …Run Code Online (Sandbox Code Playgroud) 我正面临着Firefox 8.0.1的奇怪行为:这段代码在谷歌Chrome和IE中运行良好,但在Firefox上它失败,除非我在"调试模式_一步一步"运行它或者我放了一个在我设置属性"rel"的行之后发出警报...
// some stuff before
// this piece of code works fine excepts on FF
totaltracks = data.length;
j=0;
while(j<totaltracks){
newtrack =data[j];
myPlaylist.add(newtrack);
tracks = $("a.jp-playlist-item");
curtrack = $("a.jp-playlist-item")[j];
$(curtrack).attr({rel:j});
// I tried too : $("a.jp-playlist-item")[j].attr("rel",j); with same no effect on FF
j++;
}
Run Code Online (Sandbox Code Playgroud)
似乎FF只是不照顾指令(或跳转它)如果没有一步一步完成...面对这面墙2天过去...任何帮助/线索/技巧将不胜感激
我阅读了很多相关的帖子,但找不到为什么它不适合我.我还有一个"无法大量分配受保护的属性:个人资料"......我做错了什么?
我有一个User模型和一个具有一对一关系的相关Profile模型.这里的用户模型(简化)
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :profile_attributes, :profile_id
has_secure_password
has_one :profile
accepts_nested_attributes_for :profile
end
Run Code Online (Sandbox Code Playgroud)
Profile模型
class Profile < ActiveRecord::Base
attr_accessible :bio, :dob, :firstname, :gender, :lastname, :user_id
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
我的用户控制器
def new
@user = User.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @user }
end
end
def create
@user = User.new(params[:user])
@user.build_profile
respond_to do |format|
if @user.save
format.html { redirect_to @user, flash: {success: 'User was successfully created. Welcome !'} }
format.json …Run Code Online (Sandbox Code Playgroud) nested-forms mass-assignment nested-attributes ruby-on-rails-3.2
一切都在标题中......
使用rails 3.2.11和Ransack一切正常...我添加了一项功能,让我的用户选择每页显示的项目数量,它也可以正常工作,但是当我点击sort_link时,我失去了"per_page"选项
因为我可以将其他参数传递给will_paginate
<%= will_paginate :params => {:pp => params[:pp]} %>
Run Code Online (Sandbox Code Playgroud)
有没有办法用Ransack sort_link做同样的事情?
干杯
我正在开发一个本地应用程序.我尝试将TableTools添加到我的dataTables.TableTools按钮很好地显示在页面上,但它们没有任何效果,我总是有关于swfPath的路由错误.
使TableTools在本地工作的正确方法是什么?感谢帮助
的application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap
//= require dataTables/extras/TableTools
//= require dataTables/extras/ZeroClipboard
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
users.js.coffee
jQuery ->
# Init the table
$('#users-grid').dataTable
bjQueryUI: true
sDom: 'T<"clear"><"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>'
oTableTools:
sSwfPath: "swf/copy_csv_xls_pdf.swf"
sPaginationType: "bootstrap"
bProcessing: true
bServerSide: true
sAjaxSource: $('#users-grid').data('source')
Run Code Online (Sandbox Code Playgroud)
服务器日志
Started GET "/backstage/swf/copy_csv_xls_pdf.swf" for 127.0.0.1 at 2013-02-26 11:48:11 +0100
ActionController::RoutingError (No route matches [GET] "/backstage/swf/copy_csv_xls_pdf.swf"):
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.1) …Run Code Online (Sandbox Code Playgroud)