- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编辑资源-@article
-每当我提交资源时,都会出现以下错误:
JSON::ParserError in ArticlesController#update
783: unexpected token at '#<ImageUploader::UploadedFile:0x00007fb154adb508>'
if @article.update(article_params)
Article#Update
操作中的正常Rails样板代码:
def update
respond_to do |format|
if @article.update(article_params)
format.html { redirect_to @article, notice: 'Article was successfully updated.' }
format.json { render :show, status: :ok, location: @article }
else
format.html { render :edit }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
Started PATCH "/articles/welcome-to-ftja" for ::1 at 2020-05-04 02:11:43 -0500
Processing by ArticlesController#update as HTML
Parameters: {"authenticity_token"=>"0pO56DaVEiWLX3iE3HNHRKsAPOK2z4RmUaH3jal5rOZjk7zYeoaSru9xOE9GYzLckTbnrVrz4ihXrc1hWcXzXA==", "article"=>{"title"=>"Welcome to FTJA!!", "featured"=>"true", "image"=>"#<ImageUploader::UploadedFile:0x00007fb154adb508>", "body"=>"<h1>Yet another great article.</h1><div>Test <strong>bold</strong> <em>italic</em> <del>strikethrough<br><br></del><figure data-trix-attachment=\"{"content":"<figure class=\\"attachment attachment--preview attachment--jpg\\">\\n <img src=\\"http://localhost:3000/rails/active_storage/representations/eyJfcJ2YXJpYXRpb24ifX0=--5b3d481c22cafd1ff8db36c1b24e57d8788d2217/cowork-4.jpg\\" />\\n\\n <figcaption class=\\"attachment__caption\\">\\n Coworking.\\n </figcaption>\\n</figure>\\n","contentType":"image/jpeg","filename":"cowork-4.jpg","filesize":82497,"height":768,"previewable":true,"sgid":"_ZXhwaXJlc19pbgY7AFRJIgxwdXJwb3NlBjsAVEkiD2F0dGFjaGFibGUGOwBUSSIPZXhwaXJlc19hdAY7AFQw--e56d2e422","url":"http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--6d89ec207ef10c8e48577a5e9a170a8d178a9338/cowork-4.jpg","width":752}\" data-trix-content-type=\"image/jpeg\" data-trix-attributes=\"{"caption":"Coworking.","presentation":"gallery"}\" class=\"attachment attachment--content attachment--jpg\"><figure class=\"attachment attachment--preview attachment--jpg\">\r\n <img src=\"http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--6d89ec207ef10c8e48577a5e9a170a8d178a9338/cowork-4.jpg\" width=\"752\" height=\"768\">\r\n\r\n <figcaption class=\"attachment__caption\">\r\n Coworking.\r\n </figcaption>\r\n</figure>\r\n<figcaption class=\"attachment__caption attachment__caption--edited\">Coworking.</figcaption></figure><br><br><br><figure data-trix-attachment=\"{"content":"<figure class=\\"attachment attachment--preview attachment--jpg\\">\\n <img src=\\"http://localhost:3000/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2F-5b3d481c22cafd1ff8db36c1b24e57d8788d2217/article-1.jpg\\" />\\n\\n <figcaption class=\\"attachment__caption\\">\\n Working, working, working.\\n </figcaption>\\n</figure>\\n","contentType":"image/jpeg","filename":"article-1.jpg","filesize":83730,"height":800,"previewable":true,"sgid":"BAh7CEkiCGdpZAY6BkVU--d99eadb00dd5ae6bb4220f5781b2946c2171604f","url":"http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--5c31ee2db4a2660d4a674dfb54375fda30251d3d/article-1.jpg","width":1200}\" data-trix-content-type=\"image/jpeg\" data-trix-attributes=\"{"caption":"Working, working, working.","presentation":"gallery"}\" class=\"attachment attachment--content attachment--jpg\"><figure class=\"attachment attachment--preview attachment--jpg\">\r\n <img src=\"http://localhost:3000/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9i6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQWdBRWFRSUFBdz09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--5b3d481c22cafd1ff8db36c1b24e57d8788d2217/article-1.jpg\">\r\n\r\n <figcaption class=\"attachment__caption\">\r\n Working, working, working.\r\n </figcaption>\r\n</figure>\r\n<figcaption class=\"attachment__caption attachment__caption--edited\">Working, working, working.</figcaption></figure><br><br><br></div>", "user_id"=>"1", "category_list"=>["", "Business", "Real Estate"]}, "commit"=>"Update Article", "id"=>"welcome-to-ftja"}
Article Load (2.1ms) SELECT "articles".* FROM "articles" WHERE "articles"."slug" = $1 LIMIT $2 [["slug", "welcome-to-ftja"], ["LIMIT", 1]]
↳ app/controllers/articles_controller.rb:73:in `set_article'
(2.1ms) BEGIN
↳ app/controllers/articles_controller.rb:50:in `block in update'
ActionText::RichText Load (4.0ms) SELECT "action_text_rich_texts".* FROM "action_text_rich_texts" WHERE "action_text_rich_texts"."record_id" = $1 AND "action_text_rich_texts"."record_type" = $2 AND "action_text_rich_texts"."name" = $3 LIMIT $4 [["record_id", 1], ["record_type", "Article"], ["name", "body"], ["LIMIT", 1]]
↳ app/controllers/articles_controller.rb:50:in `block in update'
(1.3ms) ROLLBACK
↳ app/controllers/articles_controller.rb:50:in `block in update'
Completed 500 Internal Server Error in 27ms (ActiveRecord: 9.4ms | Allocations: 5092)
JSON::ParserError (783: unexpected token at '#<ImageUploader::UploadedFile:0x00007fb154adb508>'):
app/controllers/articles_controller.rb:50:in `block in update'
app/controllers/articles_controller.rb:49:in `update'
category_list
,我相信可能是导致它的原因:
"category_list"=>["", "Business", "Real Estate"]},
""
引发了一些JSON解析循环。
:hybrid
,如下所示:
Rails.application.config.action_dispatch.cookies_serializer = :hybrid
>> article_params[:category_list]
=> ["", "Business", "Real Estate"]
>> article_params[:category_list].to_json
=> "[\"\",\"Business\",\"Real Estate\"]"
>> @article.image
=> #<ImageUploader::UploadedFile storage=:store id="3b96dc3198098a9f57ff2b00a2cdb252.jpg" metadata={"filename"=>"article-3.jpg", "size"=>99083, "mime_type"=>"image/jpeg"}>
SimpleForm
处理我的表单,该特定表单的截断版本如下所示:
<%= simple_form_for article, html: {multipart: true} do |f| %>
<%= f.input_field :title, placeholder: "Title", class: "form-control" %>
<%= f.rich_text_area :body, class: 'form-control customized-min-height', placeholder: "Enter your article body here..." %>
<%= f.input :user_id, as: :hidden, input_html: { value: current_user.id } %>
<%= f.input_field :category_list, collection: ActsAsTaggableOn::Tag.all.pluck(:name), input_html: { value: article.category_list.join(","), class: "custom-control-input" }, as: :check_boxes %>
<%= f.button :submit, class:"btn btn-primary" %>
<% end %>
""
时产生
Articles#Edit
Articles#Edit
Controller 操作:
# GET /articles/1/edit
def edit
end
include_blank: false
和
include_hidden: false
来获得不返回空字符串的形式,如下所示:
<%= f.input_field :category_list, collection: ActsAsTaggableOn::Tag.all.pluck(:name), input_html: { value: article.category_list.join(","), class: "custom-control-input" }, as: :check_boxes, include_blank: false, include_hidden: false %>
>> article_params
=> <ActionController::Parameters {"title"=>"Welcome!!", "body"=>"<h1>Yet another great article.</h1><div>Test <strong>bold</strong> <em>italic</em> <del>strikethrough<br><br></del><figure data-trix-attachment=\"{"content":"<figure class=\\"attachment attachment--preview attachment--jpg\\">\\n <img src=\\"http://localhost:3000/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBd2217/cowork-4.jpg\\" />\\n\\n <figcaption class=\\"attachment__caption\\">\\n Coworking.\\n </figcaption>\\n</figure>\\n","contentType":"image/jpeg","filename":"cowork-4.jpg","filesize":82497,"height":768,"previewable":true,"sgid":"BAhaac","url":"http://localhost:3000/rails/active_storage/blobs/eya9338/cowork-4.jpg","width":752}\" data-trix-content-type=\"image/jpeg\" data-trix-attributes=\"{"caption":"Coworking.","presentation":"gallery"}\" class=\"attachment attachment--content attachment--jpg\"><figure class=\"attachment attachment--preview attachment--jpg\">\r\n <img src=\"http://localhost:3000/rails/active_storage/representations/e88d2217/cowork-4.jpg\">\r\n\r\n <figcaption class=\"attachment__caption\">\r\n Coworking.\r\n </figcaption>\r\n</figure>\r\n<figcaption class=\"attachment__caption attachment__caption--edited\">Coworking.</figcaption></figure><br><br><br><figure data-trix-attachment=\"{"content":"<figure class=\\"attachment attachment--preview attachment--jpg\\">\\n <img src=\\"http://localhost:3000/rails/active_storage/representations/eyJ8d2217/article-1.jpg\\" />\\n\\n <figcaption class=\\"attachment__caption\\">\\n Working, working, working.\\n </figcaption>\\n</figure>\\n","contentType":"image/jpeg","filename":"article-1.jpg","filesize":83730,"height":800,"previewable":true,"sgid":"B1604f","url":"http://localhost:3000/rails/active_storage/blobs/eyd3d/article-1.jpg","width":1200}\" data-trix-content-type=\"image/jpeg\" data-trix-attributes=\"{"caption":"Working, working, working.","presentation":"gallery"}\" class=\"attachment attachment--content attachment--jpg\"><figure class=\"attachment attachment--preview attachment--jpg\">\r\n <img src=\"http://localhost:3000/rails/active_storage/blobs/eyd3d/article-1.jpg\" width=\"1200\" height=\"800\">\r\n\r\n <figcaption class=\"attachment__caption\">\r\n Working, working, working.\r\n </figcaption>\r\n</figure>\r\n<figcaption class=\"attachment__caption attachment__caption--edited\">Working, working, working.</figcaption></figure><br><br><br></div>", "featured"=>"true", "user_id"=>"1", "image"=>"#<ImageUploader::UploadedFile:0x00007fd18d61b1e0>", "category_list"=>["Business", "Real Estate", "Investing"]} permitted: true>
最佳答案
经过大量研究以及无穷无尽的尝试和错误,我偶然发现了此修复程序。
基本上,似乎正在发生的情况是,表单当前具有图像并且正在被编辑,如果现有图像处理不当,则会将cached_image数据转换为字符串。您可以看到better explanation here。
罪魁祸首就是我这种形式的这一行:
<%= f.input :image, as: :hidden, value: f.object.cached_image_data %>
<%= f.input :image, as: :hidden, input_html: { value: f.object.cached_image_data } %>
关于JSON解析器错误783 : unexpected token at for params,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61587022/
一旦在 qconsole Marklogic 中运行以下代码,我就会遇到以下错误 XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax err
我已经在我的包中编写了这个函数。 def partitionIntoDays(ls, number, lookupKey=None): ''' Partitions the location
我只是一个 android 初学者,我已经安装了 Android Studio(版本是 1.0.2),并创建了一个新的空白应用程序,按照名为“构建你的第一个应用程序”的官方教程,我学习到这个页面' h
这只是前几天工作,但我刚刚将我的代码更新到运行乘客 2.2.4 的审查服务器,而我的 2.3.4 rails 应用程序现在无法在那个盒子上启动。 乘客报告: Passenger encountered
我正在尝试使用带有 Angular 2的整页, 将其导入我的 app.module.ts 时出现以下错误。 "(SystemJS) Unexpected token ) at Obje
TFS2015 vNext 构建失败并出现记录器错误(下面附有错误消息)。根据我的调查,这看起来与 CentralLogger - "Microsoft.TeamFoundation.Distribu
计算机科学学校项目。我需要编写一个程序,其中用户声明数组的大小,然后以数字、非递减顺序填充数组,然后声明一个值 x。然后将 X 分配到适当的位置,以便整个数组按数字、非递减顺序排列。然后输出该数组。
在这 2 个方法中,inspect1 显示编译错误“Unexpected bound”而 inspect2 工作正常,为什么? public void inspect1(List u){ S
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我正在尝试运行以下代码,但遇到了“此时意外”错误。 (echo COPY (SELECT ta.colA as name, ta.colB as user_e, ta.colC as user_n,
我有以下查询: select u.UserName, count(*) as total from Voting v join User u using (UserID) where unique (
我们有以下查询在 MSSQL 中完美运行但在 MySQL 中无法运行: select CONVERT(datetime, dateVal) as DateOccurred, itemID, COUNT
我的代码中存在缩进错误问题。它看起来是正确的...有人能指出我做错了什么吗?我的查询行不断收到错误。 def invoice_details(myDeliveryID): conn = pym
我有以下代码: int a , b , sum; cin>>a>>b; sum=a+b; cout>a>>b>>c; cout<
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我在一个批处理文件上运行这个命令: for %I in (*.txt *.doc) do copy %I c:\test2 ...它不断返回: I was unexpected at this tim
创建查询时出现错误: 'from' unexpected 我的代码如下: @Override public Admin findByAdmin(Admin admin) {
我正在尝试运行此 python 代码,但我不断收到错误消息“意外缩进”。我不确定怎么了。间距似乎很好。有什么想法吗? services = ['Service1'] for service in
我在名为“circular_dependency”的目录中有一些 python 文件: 导入文件_1.py: from circular_dependency.import_file_2 import
我正在尝试使用 gcc 编译代码并运行可执行文件,但它抛出错误: gcc somefile.c -o somefile 编译成功。但是,当我尝试执行它时: $sh somefile 它导致:语法错误:
我是一名优秀的程序员,十分优秀!