更新
使用 has_and_belongs_to_many 让它工作
任何人都知道为什么这有效?
你好,
使用活动记录保存时出现以下错误
undefined method `reflect_on_association' for Class:Class
Run Code Online (Sandbox Code Playgroud)
我的关系是这样的:
class Contact < ActiveRecord::Base
has_many :classes
has_many :sessions, :through => :classes
end
class Class < ActiveRecord::Base
belongs_to :session
belongs_to :contact
end
class Session < ActiveRecord::Base
has_many :classes
has_many :contacts, :through => :classes
end
Run Code Online (Sandbox Code Playgroud)
我的请求看起来像这样
{"commit"=>"Submit", "contact"=>{"address"=>"", "postcode"=>"", "notes"=>"", "session_ids"=>"2", "phone"=>"", "last_name"=>"w", "email"=>"", "first_name"=>"w"}}
Run Code Online (Sandbox Code Playgroud)
session_id 和 contact_id 应该保存在类模型中
谢谢
亚历克斯
我通过get发送数据,我需要将它放入一个int数组,用于find.这是我的代码:
@found = Array.new
params['candidate'].each do |c|
@found << c.to_i
end
Run Code Online (Sandbox Code Playgroud)
我的网址看起来像这样
http://localhost:3000/export/candidate?candidate[]=3&candidate[]=4&commit=Export
Run Code Online (Sandbox Code Playgroud)
如果它有任何区别我将它用于此查找
@candidate = Candidate.find(:all, :conditions => ["candidates.id IN ?", @found])
Run Code Online (Sandbox Code Playgroud)
但是目前它没有把它放在一个真正的数组中因为我得到了这个错误
Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '4)' at line 1: SELECT * FROM `candidates` WHERE (candidates.id IN 4,2)
Run Code Online (Sandbox Code Playgroud)
数组周围缺少括号
谢谢,早上好!
亚历克斯
我正在尝试使用AJAX进度条创建一个Node.js文件上传器.
var formidable = require('./formidable'), http = require('http'), sys = require('sys');
http.createServer(function(req, res) {
if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
// parse a file upload
var form = new formidable.IncomingForm();
form.uploadDir = './node_uploads';
form.keepExtensions = true;
//print the upload status in bytes
form.addListener("progress", function(bytesReceived, bytesExpected) {
//progress as percentage
progress = (bytesReceived / bytesExpected * 100).toFixed(2);
mb = (bytesExpected / 1024 / 1024).toFixed(1);
sys.print("Uploading "+mb+"mb ("+progress+"%)\015");
});
//enter here after upload complete
form.parse(req, function(fields, files) {
sys.debug("Upload …Run Code Online (Sandbox Code Playgroud) 我有一个habtm关系(作业<assignments_candidates>候选人)
我希望能够从作业中删除一名候选人.到目前为止,这是我的代码
@assignment = Assignment.find(:first,
:joins => :candidates,
:select => "assignments_candidates.*",
:conditions => ["assignments_candidates.candidate_id = ? AND assignments_candidates.assignment_id = ?",
params[:candidate_id], params[:assignment_id]]
)
@assignment.destroy
Run Code Online (Sandbox Code Playgroud)
目前,我认为这样做会破坏对象而不是交集表中的记录
有任何想法吗 ?
谢谢,亚历克斯
我刚刚将cancan 1.5.0添加到我的rails 3应用程序这里是我的能力文件 -
def initialize(user)
user ||= User.new
if user.role == 'Admin'
can :manage, :all
end
if user.role == 'Standard'
can :manage, Library
can :manage, Page
else
can :manage, Page
can :manage, Library
end
Run Code Online (Sandbox Code Playgroud)
我有一个自定义类(非restful函数)
class PagesController < ApplicationController
authorize_resource :class => false
def home
end
end
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我正在使用正确的函数来安排一个不太安宁的类,但我仍然遇到这个错误 -
uninitialized constant Ability::Page
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪的开始 -
app/models/ability.rb:16:in `initialize'
cancan (1.5.0) lib/cancan/controller_additions.rb:327:in `new'
cancan (1.5.0) lib/cancan/controller_additions.rb:327:in `current_ability'
cancan (1.5.0) lib/cancan/controller_additions.rb:308:in `authorize!'
cancan (1.5.0) lib/cancan/controller_resource.rb:40:in `authorize_resource'
cancan (1.5.0) lib/cancan/controller_resource.rb:9:in `block in add_before_filter'
activesupport …Run Code Online (Sandbox Code Playgroud) 我试图从住宿控制器进行分页,但是使用来自MemberWall模型的数据.
这是代码
Accommodation
$data = $this->Accommodation->Member->MemberWall->paginate('MemberWall');
MemberWall
var $paginate = array(
'limit' => 4,
'order' => array(
'MemberWall.created' => 'asc'
)
);
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use nea.... Query: paginate
Run Code Online (Sandbox Code Playgroud)
谢谢,亚历克斯
我正在尝试更改保存关联时设置的属性
工厂:
Factory.define :course do |course|
course.title "Course 1"
end
Factory.define :user do |user|
user.name "Alex"
end
Run Code Online (Sandbox Code Playgroud)
执行
Factory(:course, :user => Factory(:user, name: 'Tim'))
Run Code Online (Sandbox Code Playgroud)
保存的值将是'Alex'而不是'Tim'.有任何想法吗?
我有一个搜索页面,可以找到候选人.在此页面中,您可以单击视图以查找有关候选人的更多信息.在候选视图上,您可以单击编辑或执行许多其他操作,这些操作也会使您返回候选视图.
我的问题是从候选人视图我需要添加一个按钮返回搜索结果.我最初想过使用带有历史记录-1的JS按钮,但是因为用户可以在视图中执行其他操作,所以这不起作用.
我对rails很新,所以不确定我的选择......我正在考虑某种缓存结果,然后可能是一个隐藏的字段来跟踪缓存的位置(不要认为这是最好的跟踪隐藏价值的解决方案可能会变得凌乱!)
谢谢,亚历克斯
嘿,我想一起使用 Devise 和 act_as_audited 但是当我尝试使用 -
class ApplicationController < ActionController::Base
audit Candidate
protected
def current_user
@user = User.find(user_session)
end
Run Code Online (Sandbox Code Playgroud)
我收到这个错误。
stack level too deep
Run Code Online (Sandbox Code Playgroud)
我需要以不同的方式做吗?
谢谢
我之前从未使用过WordPress,但它似乎是用户内容网站的最佳软件包.
我需要有一个主站点,它有自己的内容,但也能够为特定事件产生微型网站.
这些微型网站将有大约10页,将使用相同的模板,并需要更改其内容.
就网址而言,它可能看起来有点像这样
主要网站 - www.blog-x.com
微型网站 - www.blog-x.com/march-meetup/join
微型网页 - www.blog-x.com/march-meetup/contact
这可能与WordPress?
谢谢,亚历克斯
我希望我的select_tag默认为空白,但我正在使用地图
<%= select_tag "assignment[client_id]", options_for_select(@data.map{|d| ["#{d.first_name} #{d.last_name}",d.id]}, " ") %>
Run Code Online (Sandbox Code Playgroud)
我知道你不能使用include_blank,你不能把""设置为空白.有任何想法吗 ?
谢谢,亚历克斯
我有以下有很多通过关系
Alert AlertsElement Search
id id id
name alert_id link
search_id
ordering
Run Code Online (Sandbox Code Playgroud)
这是我的模特
class Alert extends AppModel {
var $name = 'Alert';
var $hasMany = array('AlertsElement');
class AlertsElement extends AppModel {
var $name = 'AlertsElement';
var $belongsTo = array('Alert','Search');
class Search extends AppModel {
var $name = 'Search';
var $hasMany = array('AlertsElement');
Run Code Online (Sandbox Code Playgroud)
这是我用来保存的测试代码 -
$d = array();
$d['Alert']['id'] = 1976;
$d['Search']['id'] = 107;
$d['AlertsElement']['ordering'] = 2;
$this->Alert->create();
$this->Alert->saveAll($d);
Run Code Online (Sandbox Code Playgroud)
我收到此错误 -
Cannot use a scalar value as an array [CORE/cake/libs/model/model.php, line …Run Code Online (Sandbox Code Playgroud) cakephp ×2
activerecord ×1
ajax ×1
arrays ×1
cancan ×1
devise ×1
factory-bot ×1
file-upload ×1
find ×1
javascript ×1
jquery ×1
node.js ×1
ruby ×1
wordpress ×1