以下查询的工作方式类似于魅力:
@styles = Style.search { fulltext params[:q] }
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是分页.这是与分页相同的查询:
@styles = Style.search { fulltext params[:q]; paginate :page => params[:page], :per_page => params[:page_limit] }
Run Code Online (Sandbox Code Playgroud)
我有11 Style条记录.
如果我有:page => 1,:per_page => 10当我搜索第11条记录时,我会返回一个空数组@styles.results
如果我设置:page=>2并执行相同的搜索,我将获得第11个样式记录.
[11] pry(#<StylesController>)> params[:page]=2
=> 2
[12] pry(#<StylesController>)> x=Style.search {fulltext params[:q]; paginate :page => params[:page], :per_page => params[:page_limit] }
=> <Sunspot::Search:{:fq=>["type:Style"], :q=>"hel", :fl=>"* score", :qf=>"name_textp full_name_textp", :defType=>"dismax", :start=>10, :rows=>10}>
[13] pry(#<StylesController>)> x.results
=> [#<Style id: 15...>]
Run Code Online (Sandbox Code Playgroud)
我认为重点是对搜索结果进行分页,而不是整个实际记录
这里发生了什么,我该如何解决?
编辑
好吧,让我试着用另一种方式解释.假设我有这六个记录:
1 => …Run Code Online (Sandbox Code Playgroud) 我试图按照这里的答案在地图上显示单个标记时缩小一点(默认情况下).我已经尝试了下面的代码,并生成了一个工作地图,但更改setZoom没有任何效果.此外,我从firebug收到以下错误(代码下方).
<%= gmaps("markers" => {"data" => @json, "options" => {"auto_zoom" => false} }) %>
<% content_for :scripts do %>
<script type="text/javascript" charset="utf-8">
function gmaps4rails_callback() {
if (Gmaps4Rails.markers.length == 1) {
//only one marker, choose the zoom level you expect
Gmaps4Rails.map.setZoom(5);
}
else{
//more than one marker, let's auto_zoom
Gmaps4Rails.map_options.auto_zoom = true;
Gmaps4Rails.adjust_map_to_bounds();
}
}
</script>
<% end %>
Run Code Online (Sandbox Code Playgroud)
唯一的错误是:
TypeError: Yc is not a function
[Break On This Error]
...=b}Rf[F].Fa=xk(7,Yc("f"));me[F].cb=xk(3,function(a){var b;if(b=a.ca[ec]()?j:a.ca...
Run Code Online (Sandbox Code Playgroud) 嗨,我想做以下工作:
http://localhost:3000/reviews/new?ticket[]=token[]=109u11
Run Code Online (Sandbox Code Playgroud)
它可以被认为是意义 params[:ticket][:token] = 109u11
谢谢!
我收到以下错误:
undefined method `can_read?' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
..当试图访问已注销用户的产品页面时.目前我有
class ProductAuthorizer < ApplicationAuthorizer
def self.readable_by?(user)
true
end
end
Run Code Online (Sandbox Code Playgroud)
我想允许甚至未登录的用户查看该页面.这可能吗?
我尝试将默认用户方法更改为:
config.user_method = :current_user ||= User.new
Run Code Online (Sandbox Code Playgroud)
但是,这会导致问题,我的服务器甚至都无法启动.
在我的控制器中,如果用户已退出,我将重定向用户.然后我拉了一个专业人员列表..如果不存在,也需要重定向.有没有办法解决这个难题?
def purchase
@style = Style.find(params[:id])
if user_signed_in? && current_user.consumer
@professionals = Professional.where(...)
if @professionals.empty?
redirect_to style_path(@style)
else
...
end
...
else
flash[:error] = "Please sign in as a consumer to access this page"
redirect_to style_path(@style)
end
end
Run Code Online (Sandbox Code Playgroud) 在 Gmail 中,以下电子邮件地址
class UserMailer < ActionMailer::Base
default from: 'no-reply@example.com'
end
Run Code Online (Sandbox Code Playgroud)
变成这个(第二项)

无论如何让“发件人”地址为“无回复”但发件人名称更有意义吗?
我注意到我的电子邮件表单 SumAll 呈现为来自“SumAll”,但对地址的回复不同,如下所示:
From: =?utf-8?Q?SumAll?= <mailing@sumall.com>
Run Code Online (Sandbox Code Playgroud)
知道如何使用 Action Mailer 管理这个吗?
这是我以前在Rails 3中使用过的表单:
<%= form_for Style.new do |s| %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
抛出错误: nil的未定义方法`param_key':NilClass
完整跟踪:
NoMethodError - undefined method `param_key' for nil:NilClass:
actionview (4.2.0.rc2) lib/action_view/helpers/form_helper.rb:433:in `form_for'
app/views/styles/_add_style_form.html.erb:1:in `_app_views_styles__add_style_form_html_erb__4060888642586793101_94112200'
actionview (4.2.0.rc2) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.0.rc2) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.0.rc2) lib/action_view/template.rb:143:in `render'
xray-rails (0.1.14) lib/xray/engine.rb:33:in `render_with_xray'
actionview (4.2.0.rc2) lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
actionview (4.2.0.rc2) lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
actionview (4.2.0.rc2) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Select2 jquery插件进行AJAX调用.查询似乎有效,但.results()在options对象上调用时会出现问题:
Uncaught TypeError: options.results is not a function
这是我的HTML:
<input class="form-control" type="number" value="2125" name="topic_relation[source_topic_id]" id="topic_relation_source_topic_id" />
Run Code Online (Sandbox Code Playgroud)
这是我的JS:
$(document).ready(function() {
$('#topic_relation_source_topic_id').select2({
minimumInputLength: 3,
ajax: {
url: "<%= grab_topics_path %>",
dataType: 'json',
delay: 250,
data: function (term, page) {
return {
q: term, //search term
page_limit: 30, // page size
page: page, // page number
};
},
processResults: function (data, page) {
var more = (page * 30) < data.total;
return {results: data.topics, more: more};
}
}, …Run Code Online (Sandbox Code Playgroud) 当我跑步时,stencil bundle我看到以下内容:
? cornerstone git:(master) ? stencil bundle
Validating theme...
Running ESLint...
/Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/config/config-file.js:402
throw e;
^
Error: Cannot find module 'eslint-config-airbnb/base'
Referenced from: /Users/xxx/bigcommerce/cornerstone/.eslintrc
at Object.ModuleResolver.resolve (/Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/util/module-resolver.js:75:19)
at resolve (/Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/config/config-file.js:479:33)
at load (/Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/config/config-file.js:496:24)
at /Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/config/config-file.js:392:36
at Array.reduceRight (native)
at applyExtends (/Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/config/config-file.js:363:28)
at Object.load (/Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/config/config-file.js:530:22)
at loadConfig (/Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/config.js:64:33)
at getLocalConfig (/Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/config.js:126:23)
at Config.getConfig (/Users/xxx/.nvm/versions/node/v4.4.0/lib/node_modules/@bigcommerce/stencil-cli/node_modules/eslint/lib/config.js:227:22)
Run Code Online (Sandbox Code Playgroud)
我最初跑的时候npm install看到了这个:
? cornerstone git:(master) npm install
npm WARN deprecated minimatch@0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS …Run Code Online (Sandbox Code Playgroud)