我正在尝试对产品进行分页。我有:
# Routes
match 'dashboard' => 'dashboard#index'
# Dashboard Controller
def index
@products = Product.order("id").page(params[:page]).per_page(4)
end
# Dashboard Index View
h1 products
.products
= render @products
= will_paginate(@products)
Run Code Online (Sandbox Code Playgroud)
分页链接显示在仪表板索引视图中。
例子
<-- previous 1 2 3 next -->
Run Code Online (Sandbox Code Playgroud)
但链接没有附加正确的路径。默认视图是 localhost:3000/dashboard。
分页链接有:
http://localhost:3000/?page=2
Run Code Online (Sandbox Code Playgroud)
为了测试,如果我只是在网址栏中输入带有页面参数的正确路径
http://localhost:3000/dashboard?page=2
Run Code Online (Sandbox Code Playgroud)
它工作正常并且可以分页,显示下一组产品。我的目标是让链接有dashboard在链接中。我猜测这会通过视图中“will_paginate”方法中传递选项的某些组合来发生。
我希望当用户位于根页面时发生这种情况:
http://localhost:3000/dashboard
Run Code Online (Sandbox Code Playgroud) 我试图绕过默认的friendly_id方法,该方法验证特定slug上的uniq值.简而言之,我想绕过具有相同值的slug的friendly_id检查,并且它不会附加--1, - 2等.我需要能够使用friendly_id创建记录,这些记录都可以具有相同的段塞文本.
class Product < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: :slugged # use the title column to create slug column
Run Code Online (Sandbox Code Playgroud) 痛苦地获得活动管理员以对关联的子列进行排序.我有一个有相关"用户"的个人资料.
ActiveAdmin.register Profile, as: "Member" do
def scoped_collection
end_of_association_chain.includes(:user)
end
column "Referral", sortable: 'user.referrals' do |member|
member.user.referrals
end
--error when sorting---
PG::Error: ERROR: syntax error at or near "."
LINE 1: ... "users"."id" = "profiles"."user_id" ORDER BY user.referrals...
^
: SELECT "profiles"."id" AS t0_r0, "profiles"."actor_id" AS t0_r1,
Run Code Online (Sandbox Code Playgroud) 很难正确地进行本地设置.试图管理领班并解决问题:
web: bundle exec thin -R config.ru start -p $PORT -e ${RACK_ENV:-development}
RACK_ENV:"FACEBOOK_APP_ID=275479742529226"
RACK_ENV:"FACEBOOK_SECRET=xxx"
Run Code Online (Sandbox Code Playgroud)
跑"工头开始"
15:21:21 RACK_ENV.1 | process terminated
15:21:21 web.1 | started with pid 23406
15:21:21 system | sending SIGTERM to all processes
15:21:21 RACK_ENV.1 | started with pid 23407
15:21:21 system | sending SIGTERM to pid 23406
15:21:21 RACK_ENV.1 | started with pid 23408
15:21:21 RACK_ENV.1 | /Users/mc/.rvm/gems/ruby- 1.9.2-p290/gems/foreman-
0.41.0/bin/foreman-runner: line 36: exec: "FACEBOOK_APP_ID=275479742529226": not found
Run Code Online (Sandbox Code Playgroud)
显然我设置我的fb键完全不正确的env ..如果有人可以帮忙.我已经尝试在根目录中设置.env文件,其中包含
FACEBOOK_APP_ID = 964173273189 FACEBOOK_SECRET = xxx
删除proc文件中的所有内容(我认为它是不正确的)和运行的foreman,默认情况下它不应该在根目录中拾取.env文件吗?这没有证明任何运气.
5:44:20 web.1 …Run Code Online (Sandbox Code Playgroud) 我有一个名为"汽车"的模型
我想知道如何在模型中声明,这样当两个属性相互匹配时,只能存在一条记录.例如,在汽车模型中
:owner_id, :driver_id
Run Code Online (Sandbox Code Playgroud)
假设存在一条记录:
:id => "1", :owner_id => "22", :driver_id => "23", :state => "parked"
Run Code Online (Sandbox Code Playgroud)
如果我尝试创建另一条记录,它也具有相同owner_id且driver_id相互匹配的记录,则记录将无法创建自己.我正在尝试建立一个关系模型,在匹配时为每个所有者和驱动程序创建一条记录.
activeadmin ×1
activerecord ×1
admin ×1
facebook ×1
foreman ×1
friendly-id ×1
heroku ×1
routes ×1