我已经阅读了很多像这样的底池,但我看到的所有解决方案都在模型,命名和Rails惯例的命名中.
现在,当我在PostgreSQL 9.1中的生产环境中第一次运行时,我遇到了这个问题
rake db:migrate RAILS_ENV=production
Run Code Online (Sandbox Code Playgroud)
要么
rake db:schema:load RAILS_ENV=production
Run Code Online (Sandbox Code Playgroud)
我可以毫无问题地创建数据库:rake db:create RAILS_ENV=production
=>好的
错误是
rake aborted!
PG::UndefinedTable: ERROR: relation "categories" does not exist
LINE 5: WHERE a.attrelid = '"categories"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"categories"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
Run Code Online (Sandbox Code Playgroud)
这些模型遵循所有Rails命名约定.所以,我不知道这个错误告诉我 什么?还有其他什么可以导致这个错误?
型号:
class Category …
Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 4上的jquery-file-upload,我是从https://github.com/tors/jquery-fileupload-rails-paperclip-example开始的.所以我使用的是jquery-rails,jquery-fileupload-rails和paperclip gems.
由于我不是jquery或javascript的破解,我正在尝试简化和理解所有内容,更改代码以使用js.erb远程调用rails.
所以,文件列表是rails部分(_videos.html_erb),上传控制器中的索引操作有一个index.js.erb来响应js.我已经$.get('/uploads');
在de fileupload done
事件中添加了刷新部分.
一切顺利,除非取消按钮,我不明白我要做什么,在哪里.
这是文档告诉我的:
如何取消上传
可以通过在jqXHR对象上调用abort方法来取消上载:
var jqXHR = $('#fileupload').fileupload('send', {files: filesList})
.error(function (jqXHR, textStatus, errorThrown) {
if (errorThrown === 'abort') {
alert('File Upload has been canceled');
}
});
$('button.cancel').click(function (e) {
jqXHR.abort();
});
Run Code Online (Sandbox Code Playgroud)
这是我的index.html.erb:
这里,对于进度条和文本指示,我把代码提取为file-upload-basic-plugin
<div class="container">
<h2 id="titol">Upload file</h2>
<%= form_for Upload.new, :html => { :multipart => true, :id => "fileupload" } do |f| %>
<div class="row fileupload-buttonbar">
<%= f.file_field :upload %>
<button …
Run Code Online (Sandbox Code Playgroud) 就在appdelegates,applicationDidBecomeActive.我创建并启动一个线程,该线程等待异步下载,然后保存数据:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// begins Asynchronous download data (1 second):
[wsDataComponents updatePreparedData:NO];
NSThread* downloadThread = [[NSThread alloc]
initWithTarget:self
selector: @selector (waitingFirstConnection)
object:nil];
[downloadThread start];
}
Run Code Online (Sandbox Code Playgroud)
然后
-(void)waitingFirstConnection{
while (waitingFirstDownload) {
// Do nothing ... Waiting a asynchronous download, Observers tell me when
// finish first donwload
}
// begins Synchronous download, and save data (20 secons)
[wsDataComponents updatePreparedData:YES];
// Maybe is this the problem ?? I change a label in main view controller
[menuViewController.labelBadgeVideo setText:@"123 videos"];
// Nothig …
Run Code Online (Sandbox Code Playgroud) 考虑到这些参数:
"product"=><ActionController::Parameters {"id"=>"",
"category_ids"=><ActionController::Parameters {"2"=>"1", "3"=>"1", "4"=>"1"} ,
"name"=>"...", "description"=>"a good prod", "size"=>"2x3m", "price"=>"23$", "url_video"=>"http://...", "remarks"=>"bla"}
Run Code Online (Sandbox Code Playgroud)
我想CATH category_ids PARAMS { "2"=> "1", "3"=> "1", "4"=> "1"}用正确的permit
和require
sintax,比我不知道:
执行时
params.require(:product).permit(:name, :size,..., category_ids: [] )
Run Code Online (Sandbox Code Playgroud)
结果是
Unpermitted parameters: id, category_ids
Run Code Online (Sandbox Code Playgroud)
我试过params.require(:product).permit(:category_ids[:id,:val])
......和其他变种
什么是正确的sintax?
PD:这些参数是例如:
<input type="checkbox" name="product[category_ids][2]" id="product_category_ids_2" value="1">
<input type="checkbox" name="product[category_ids][3]" id="product_category_ids_3" value="1">
Run Code Online (Sandbox Code Playgroud)
为了一个has_and_belongs_to_many
关系
class Product < ActiveRecord::Base
has_many :images, dependent: :destroy
has_and_belongs_to_many :categories, autosave: true
attr_accessor :category_list
end
class Category < ActiveRecord::Base
has_and_belongs_to_many :products …
Run Code Online (Sandbox Code Playgroud) Rubocop说这条线太长
if paragraph.update(picture:
contact_params[:menucontact_attributes][:paragraphs_attributes]['0'][:picture])
Run Code Online (Sandbox Code Playgroud)
如何拆分contact_params[:menucontact_attributes][:paragraphs_attributes]['0'][:picture])
成多行?