之前我做过一个项目也是站内消息,也发生过执行 2 次方法将消息的状态变为已读,后面发现是 rails 自带的 turbolinks 有问题,然后升级 turbolinks 的版本后问题就没有出现过了
:plus1:
顶楼上,就是楼上说的那样做,然后 Course.first.datums 才能显示第一个课程对应资料
共产党躺枪!
直接点赞
很不错,设计很棒!
#5 楼 @1010printing_com 刚学才一年,恐怕能力不足啊,哈哈!
惠州的帮顶一下吧,还没见过在这边发过招聘呢!
$sudo vim /etc/mysql/my.cnf #运行配置文件
#修改配置文件
[client]
default-character-set = utf8
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
init_connect = 'SET NAMES utf8'
default-time-zone = '+8:00'
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
你试试按照上面的代码添加在 mysql 配置文件里,然后看看行不行
这问题我以前好像遇到过,mysql 需要设置相应的东西的,不然就会报错
#5 楼 @a4652097 你这 Category has_many Article? 是的话看下面 如果只是简单的 category_id 排列
@article = Article.paginate(:page => params[:page], :per_page => 5).reorder(category_id: :desc)
如果是要根据搜索出来的 category 的 id 进行排列就下面这样
@articles = Article.all
@articles = @articles.joins(:category).where("categories.id = ?",params[:id] )
@articles = @articles.paginate(:page => params[:page], :per_page => 5).reorder(created_at: :desc)
要根据 category 的 id 来对@article进行排列?
可以的,我刚开始什么各种语言都不会,一样学!
凑子查询是为了能将数据合并起来方便使用
这个 select 里面只要超过一个就会发生报错
2.1.2 :016 > User.select("id, name")
User Load (0.6ms) SELECT id, name FROM `users`
=> #<ActiveRecord::Relation [#<User id: 5, name: "admin">, #<User id: 6, name: "test">]>
2.1.2 :017 > User.select("id, name").count
(0.6ms) SELECT COUNT(id, name) FROM `users`
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' name) FROM `users`' at line 1: SELECT COUNT(id, name) FROM `users`
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' name) FROM `users`' at line 1: SELECT COUNT(id, name) FROM `users`
当 select 里面只有一个的时候
2.1.2 :021 > User.select("id").count
(0.6ms) SELECT COUNT(`users`.`id`) FROM `users`
=> 2
2.1.2 :022 >
这就没问题,我想,不应该是多了子查询而发生错误!
include SeesionHelper 这里错了
应该是 include SessionHelper
#1 楼 @chaixl 看过 2 遍了,但是现在这是实际的东西,跟书本里面的例子有一些比较大的出入
#2 楼 @paranoyang 这个没必要写多 3 个子类
#4 楼 @Kabie @willmouse 这个方法是在 controller 里面调用的,而 controller 是需要根据返回的布尔值进行下一步操作的。
#7 楼 @billy 这个是在 models concerns 下 project_support.rb 的方法,在 model 是通过 extend ProjectSupport 代码将其引入的,所以 restore_record 确实是一个 class method,而 deleted 是 gem paranoia 的 only_deleted 方法,activities 是 controller 里调用 restore_record 方法时所引入的一个值