有没有人知道在WKWebView中禁用双击和缩放缩放的简单方法?我没有尝试过任何工作:
Webview.scrollView.allowsMagnification = false; // Error: value of type WKWebView has no member allowsMagnification
Webview.scrollView.isMultipleTouchEnabled = false; // doesn't do anything
Run Code Online (Sandbox Code Playgroud)
在html中:
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> // pile of crap, does nothing
Run Code Online (Sandbox Code Playgroud) 我在地图上有一堆传单标记.每个标记保持在阵列中markers
.标记是动态创建的(在ajax调用期间).
var markers = [];
.
.
var marker = L.marker([mar.lat, mar.lng], {
// ...build the marker...
}
marker._leaflet_id = mar.id; // give the marker an id corresponding to the id of its corresponding div
var myHoverIcon = L.icon({
iconUrl: mar.imgUrl,
iconSize: [40, 40],
popupAnchor: [0, 0]
});
marker.on('click', function(e) {
alert('Marker clicked!');
marker.setIcon(myHoverIcon);
});
.
.
markers.push(marker);
Run Code Online (Sandbox Code Playgroud)
每个标记具有对应于特定div的id(存储在data-mess_id
div中).计划是在单击Feed中相应的div时更改标记的图标.
$('#feed').on('mouseover', '.message', function() {
var cssid = $(this).attr('data-mess_id').toString();
var baz = $.grep(markers, function(m) {
return (m._leaflet_id == …
Run Code Online (Sandbox Code Playgroud) users_controller.rb:
@search_results = Notice.search('hello')
if(params[:query])
@search_results = Notice.search(params[:query])
end
Run Code Online (Sandbox Code Playgroud)
Notice.rb:
def self.search(search)
if search
Notice.where("content LIKE ?", "%#{search}%")
else
end
end
Run Code Online (Sandbox Code Playgroud)
在视图中:
<%= render 'shared/search_results' %>
Run Code Online (Sandbox Code Playgroud)
_search_results.html.erb部分:
<% if @search_results.any? %>
<ol class="notices">
<%= render @search_results %>
</ol>
<%= will_paginate @search_results %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我收到错误:undefined method total_pages for #<Notice::ActiveRecord_Relation:0x0000010f3e8888>
.
(这一切都很好,没有分页.)
我该如何解决这个错误?
成功为卡创建令牌后,我可以成功访问以下属性:
token.card.id # => "card_1E4YHkEyZ1SEBQHCiMrFatPq"
token.card.brand # => "Visa"
token.card.name # => "Jenny Rosen"
Run Code Online (Sandbox Code Playgroud)
但是,这失败了:
token.card.fingerprint # => undefined
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?有没有其他人有这个问题?
这个想法是为了让管理员用户无法自我毁灭.我写了以下测试:
describe "as admin user" do
let(:admin) { FactoryGirl.create(:admin) }
before { valid_signin admin }
describe "should not be able to delete himself by submitting a DELETE request to the Users#destroy action" do
specify do
expect { delete user_path(admin) }.not_to change(User, :count).by(-1)
end
end
end
Run Code Online (Sandbox Code Playgroud)
并修改了破坏行动:
def destroy
@user = User.find(params[:id])
unless current_user?(@user)
User.find(params[:id]).destroy
flash[:success] = "User destroyed."
redirect_to users_url
end
end
Run Code Online (Sandbox Code Playgroud)
(如果您是管理员用户,则只能访问销毁操作).
测试现在应该通过,但事实并非如此.我收到以下错误消息:
Failure/Error: expect { delete user_path(admin) }.not_to change(User, :count).by(-1)
ActionView::MissingTemplate:
Missing template users/destroy, application/destroy with {:locale=>[:en], :formats=>[:html], …
Run Code Online (Sandbox Code Playgroud) 这段代码来自Ryan Bates的Railscast第343集,内容是关于PostgreSQL中的全文搜索.我想理解它,但我在<<-
操作员身上找不到任何东西(如果它甚至是操作员).有人可以指点我到某个地方,我可以了解这个吗?
rank = <<-RANK
ts_rank(to_tsvector(name), plainto_tsquery(#{sanitize(query)})) +
ts_rank(to_tsvector(content), plainto_tsquery(#{sanitize(query)}))
RANK
Run Code Online (Sandbox Code Playgroud) 用户可以通过has_many关联投票给帖子.我从运行测试中收到此错误:
ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type integer
Run Code Online (Sandbox Code Playgroud)
从这个测试:
test "should unvote a post the standard way" do
@user.vote(@post_2)
postvoterelationship = @user.active_post_vote_relationships.find_by(voted_id: @post_2.id)
assert_difference '@user.postvoting.count', -1 do
delete postvoterelationship_path(postvoterelationship)
end
end
Run Code Online (Sandbox Code Playgroud)
postvoterelationships_controller.rb
def destroy
@user = Postvoterelationship.find(params[:id]).voter
@post = Postvoterelationship.find_by(params[:id]).voted
@user.unvote(@post)
respond_to do |format|
format.html do
redirect_to @user
end
format.js
end
end # destroy
Run Code Online (Sandbox Code Playgroud)
的routes.rb
resources :postvoterelationships, only: [:create, :destroy]
Run Code Online (Sandbox Code Playgroud)
postvoterelationship.rb
class Postvoterelationship < ActiveRecord::Base
belongs_to :voter, class_name: "User"
belongs_to :voted, class_name: "Post"
validates …
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行'rails console'并且我不断收到以下错误消息:
在normalize_conditions!': You should not use the
匹配途中method in your router without specifying an HTTP method. (RuntimeError)
If you want to expose your action to both GET and POST, add
:[:get,:post] option.
If you want to expose your action to GET, use
get`在路由器中:而不是:匹配"控制器#动作"执行:获取"控制器#动作"
我无法在Stack Overflow上找到解决方案,我该怎么办?
我的routes.rb文件是:
Myapp::Application.routes.draw do
resources :users do
member do
get :following, :followers
end
end
resources :sessions, only: [:new, :create, :destroy]
resources :microposts, only: [:create, :destroy]
resources :relationships, only: [:create, :destroy]
root to: 'static_pages#home' …
Run Code Online (Sandbox Code Playgroud) 这是你知道如果你知道答案就会让你觉得愚蠢的问题之一,但我不能让这件事情起作用,所以这里就是这样.在railstutorial.org中我试图解决第10章末尾的练习5但是下面的代码有问题,我尝试的每个变体(例如使用'除')都不起作用.如果当前用户不是管理员用户,我只想执行两行代码.我哪里错了?
def destroy
if !current_user.admin?
User.find(params[:id]).destroy
flash[:success] = "User destroyed."
end
redirect_to users_path
end
Run Code Online (Sandbox Code Playgroud)
编辑:我将当前用户与要删除的用户混淆.我正在使用Aditya的代码,我确信它是正确的,但现在我收到一条"无法运行测试"的消息,表明我的测试中存在语法错误(如下).
describe "as an admin user" do
before(:each) do
admin = Factory(:user, :email => "admin@example.com", :admin => true)
test_sign_in(admin)
end
it "should not allow an admin user to destroy himself" do
lambda do
delete :destroy, :id => admin
end.should_not change(User, :count)
end
end
Run Code Online (Sandbox Code Playgroud) 编译后我收到此错误:
error: incompatible types: <anonymous WebViewClient> cannot be converted to Context
Run Code Online (Sandbox Code Playgroud)
错误来自这一行:
progress = ProgressDialog.show(this, "", "Loading...", true);
Run Code Online (Sandbox Code Playgroud)
this
Context
我认为这是一个类,我认为它与此有关,我不明白上下文是什么或如何解决它.
MainActivity.java
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String urlNewString) {
webView.loadUrl("http://www.google.com");
return true;
}
@Override
public void onPageStarted(WebView webView, String url, Bitmap facIcon) {
progress = ProgressDialog.show(this, "", …
Run Code Online (Sandbox Code Playgroud)