在我的rails应用程序中,我有一个ajax请求到服务器,以存储一些数据.这曾经没有任何问题,但现在我收到一个错误:
ActionController::UnknownFormat (ActionController::UnknownFormat):
app/controllers/reservations_controller.rb:45:in `create'
Run Code Online (Sandbox Code Playgroud)
以下是控制器和我的javascript文件,其中我声明数据类型是JSON
class ReservationController < ApplicationController
respond_to :html, :json
def create
...
respond_to do |format|
if @reservation.save
format.html do
redirect_to '/'
end
format.json { render json: @reservation.to_json }
else
render 'new'
end
end # respond_to
end # create
end # ReservationController
Run Code Online (Sandbox Code Playgroud)
function.js
$.ajax({
url: url_link,
dataType: 'json',
type: 'POST',
data: dataToSend
})
Run Code Online (Sandbox Code Playgroud)
完整的错误日志是:
Completed 406 Not Acceptable in 45ms
ActionController::UnknownFormat (ActionController::UnknownFormat):
app/controllers/bookings_controller.rb:45:in `create'
Rendered /Users/tiagovieira/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.5ms)
Rendered /Users/tiagovieira/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.8ms)
Rendered /Users/tiagovieira/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
Rendered /Users/tiagovieira/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout …
Run Code Online (Sandbox Code Playgroud) 我在Bitbucket中添加了ssh密钥.如果我这样做,ssh -T git@bitbucket.org
他说我已经登录了.但是当我做一个git push/pull时,我收到以下消息
conq: repository does not exist.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
我的cat .git/config
产出:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = git@bitbucket.org:myUserName/myGitRepo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "heroku"]
url = git@heroku.com:herokuUrl.git
fetch = +refs/heads/*:refs/remotes/heroku/*
[branch "somebranch"] …
Run Code Online (Sandbox Code Playgroud) 我正试图标记N + 1并在代码中放置我可以使用bullet gem添加计数器缓存.但是手动完成所有操作来检查N + 1查询,看起来非常痛苦,所以我尝试使用Bullet和Rspec,使用他们推荐的设置步骤:
# config/environments/test.rb
config.after_initialize do
Bullet.enable = true
Bullet.bullet_logger = true
Bullet.raise = true # raise an error if n+1 query occurs
end
# spec/spec_helper.rb
if Bullet.enable?
config.before(:each) do
Bullet.start_request
end
config.after(:each) do
Bullet.perform_out_of_channel_notifications if Bullet.notification?
Bullet.end_request
end
end
Run Code Online (Sandbox Code Playgroud)
但是当我运行规范时,似乎在规范本身而不是应用程序中标记N + 1个查询.你知道是否有可能达到我的目的吗?
如何放大/缩小地图视图以覆盖所有标记?
我正在审查sdk中给出的gmap V2的示例代码.它放在sdk\extras\google\google_play_services\samples\maps上.
提前致谢.
我刚刚在我的应用程序上安装了Devise,我之前已经像迈克尔哈特教程那样在头上完成了它.
目前我可以注册并注销.但是当我登录时会出错:
No route matches [POST] "/sessions/user"
当我点击登录/登录按钮时,无论是否有(正确的)密码,都会发生这种情况.
我的路线文件是:
SampleApp::Application.routes.draw do
devise_for :users, path_names: { sign_in: "login", sign_out: "logout"}
resources :users do
resources :bookings, only: [:show]
end
resources :bookings
resources :sessions
# match '/signup', to: 'devise/registrations#new', via: :get
# match '/signin', to: 'devise/sessions#new', via: [:post, :get]
# match '/signout', to: 'devise/sessions#destroy', via: :delete
match '/admin', to: 'admin#new', via: :get
match "bookings/new", to: 'bookings#new', via: [:post, :get]
devise_scope :user do
root to: 'static_pages#home'
end
Run Code Online (Sandbox Code Playgroud)
[编辑]
我的表单是设计的默认形式:
<h2>Sign in</h2>
<%= form_for(resource, :as …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ActiveJob
诸如电子邮件调度之类的队列作业,但我得到了一个
NotImplementedError (Use a queueing backend to enqueue jobs in the future.
错误
将更新提交到数据库后,在我的model.rb
文件中
class Article < ActiveRecord::Base
include ActiveModel::Dirty
require './app/jobs/email_scheduler_job'
def send_approved_mail
if self.approved_was == false && self.approved
ArticleMailer.article_approved(self.owner).deliver_later
EmailSchedulerJob.set(wait: 2.weeks).perform_later(owner)
end
end
end
Run Code Online (Sandbox Code Playgroud)
并在我的EmailSchedulerJob
class EmailSchedulerJob < ActiveJob::Base
queue_as :default
def perform(*args)
# Do something later
end
end
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我已经有上传图片的回形针,但需要更改以接受图像和视频.图像已经在具有belongs_to
关系的模型中定义,称为Attachment
.由于视频也将是相同父模型的附件(在我的案例中,文章),我想Attachment
为图像和视频重用相同的模型.这是一个好主意吗?
我的代码 attachment.rb
是:
class Attachment < ActiveRecord::Base
belongs_to :article
has_attached_file :url, :s3_protocol => :https ,
styles: {
medium: "300x300>", thumb: "100x100>", big: "1200x1200>", normal: "600x600>"
}
validates_attachment_content_type :url, content_type: /\Aimage|\Avideo\/.*\Z/
validates_attachment :url, content_type: { content_type: ["image/jpeg", "image/gif", "image/png", "video/mp4"] }
end
Run Code Online (Sandbox Code Playgroud)
但事实并非如此,它并没有在S3上存储视频.我在终端上得到以下内容
Command :: file -b --mime '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/f3e2afc957bb9fb2aa3e77e69359c48920160131-13311-pyeez1.mp4'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An …
Run Code Online (Sandbox Code Playgroud) 我的 Rails 应用程序有一个远程数据库,我可以在其中独立于应用程序创建和存储表,而且它是“无模型的”,我不需要或不需要这些表的模型或 ORM。要访问数据,我使用一个简单的ActiveRecord::Base.connection.execute(query)
命令。
我schema.rb
有很多这样的评论消息:
# Could not dump table "geographic_data" because of following StandardError
# Unknown type 'geometry(MultiLineString,4326)' for column 'geom'
Run Code Online (Sandbox Code Playgroud)
我的问题/怀疑:
如果我安装 ActiveRecord PostGIS 适配器,它会清除我在这些非模型表中已有的所有数据吗?这是一种可能的情况吗?
我正在做一个 Rails 应用程序,它主要是一个 API。我正在尝试测试我的 API 端点的控制器。我的 RSpec 控制器测试仪如下:
require 'rails_helper'
require 'spec_helper'
require 'rack/test'
require 'devise'
class RoutesControllerTest < ActionController::TestCase
describe "User with token"
test "should post route" do
params = { route: { start_lat: 38.7627951, start_long: -9.1532211,
end_lat: 38.7483783, end_long: -9.155045,
flag_opt: 0.4, city: 1 }
}
post '/routes.json' , params.to_json, format: :json
assert_response :success
end
end
end
Run Code Online (Sandbox Code Playgroud)
我的控制器是:
class RoutesController < ApplicationController
def create
city = City.find(params[:route][:city])
user = current_user
@route = user.routes.new(route_params)
@results = @route.calc_route(@route.start_long, @route.start_lat, @route.end_long, …
Run Code Online (Sandbox Code Playgroud) 在我的 html 表单中,我有两种不同类型的输入,其$scope
变量与模型相同。
我有 3 个单选按钮和一个数字输入字段
<div class="form-group">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" ng-model="article.internal_memory" value="16" name="options" id="option1" > 16GB
</label>
<label class="btn btn-primary">
<input type="radio" ng-model="article.internal_memory" value="32" name="options" id="option2" > 32GB
</label>
<label class="btn btn-primary">
<input type="radio" ng-model="article.internal_memory" value="64" name="options" id="option3" > 64GB
</label>
</div>
<input ng-model="article.internal_memory" id="internal-memory-input" placeholder="Outra" type="number" class="form-control">
</div>
Run Code Online (Sandbox Code Playgroud)
但是,如果我选择其中一个单选按钮输入,它不会设置该值。
同一个作用域变量有两个不同的输入会导致冲突吗?
ruby ×3
angularjs ×2
rspec ×2
activerecord ×1
ajax ×1
android ×1
bitbucket ×1
devise ×1
git ×1
javascript ×1
json ×1
paperclip ×1
postgresql ×1
respond-to ×1