小编Wor*_*ica的帖子

Rails控制台无法连接到数据库

在最后几天,我将我的OS X更新为Maverics.今天,当我尝试创建这样的新项目时:

rails new abc
Run Code Online (Sandbox Code Playgroud)

有很多问题,但我安装xcode,现在它的工作.现在我打开rails控制台,如下所示:

rails console
Run Code Online (Sandbox Code Playgroud)

然后无论我写什么我只看到:

Loading development environment (Rails 4.0.1)
1.9.3p448 :001 > Link
=> Link(no database connection)
Run Code Online (Sandbox Code Playgroud)

怎么了?Mysql正在运行,数据库存在.当我做rake db:migrate时一切正常.

macos ruby-on-rails

27
推荐指数
3
解决办法
7690
查看次数

用户root访问被拒绝 - MAC OS上的mysql

我知道怎么在ubuntu上跳过这个问题,但我怎么能在MAC OS上做呢?

如何在MAC上设置mysql的密码?

1)不起作用

mysqladmin -u root password NEWPASSWORD
Run Code Online (Sandbox Code Playgroud)

2)不起作用

mysqld --skip-grant-tables --skip-networking &
Run Code Online (Sandbox Code Playgroud)

3)这有效:

mysql root密码忘记了

mysql macos

11
推荐指数
5
解决办法
4万
查看次数

Rails考拉宝石和朋友数

有人可以帮助我获得total_count的用户朋友吗?

u.facebook.get_connection("me", "friends",api_version:"v2.0")
Run Code Online (Sandbox Code Playgroud)

这返回0因为它返回也使用我的应用程序的朋友.

但是在api 2.0 facebook中,将total_count字段与朋友号码一起给出

{
  "data": [
  ], 
  "summary": {
    "total_count": 455
  }
}
Run Code Online (Sandbox Code Playgroud)

我如何通过考拉宝石获得这个?

u.facebook.get_connection("me", "friends/#{summary}",api_version:"v2.0")
Run Code Online (Sandbox Code Playgroud)

这个返回错误.

答案如果有人会搜索这个:

facebook.get_connection("me", "friends",api_version:"v2.0").raw_response["summary"]["total_count"]
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails facebook-graph-api koala

10
推荐指数
1
解决办法
876
查看次数

设计确认_token无效

我的User.rb:

class User < ActiveRecord::Base

    devise :database_authenticatable, :registerable,:confirmable,:token_authenticatable,
     :recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:name]
Run Code Online (Sandbox Code Playgroud)

我的路线:

devise_for :users, :controllers => { :sessions => "sessions", :confirmations => "confirmations", :passwords => "passwords", :registrations => "registrations" }
Run Code Online (Sandbox Code Playgroud)

我的ConfirmationsController是一个标准控制器,但具有不同的重定向.

我的电子邮件链接如下:

/users/confirmation?confirmation_token=167bad44a15e02b0bd570b51e1bf927b88368d8855d92b9833a24017a2bad4be
Run Code Online (Sandbox Code Playgroud)

在数据库用户有

confirmation_token:167bad44a15e02b0bd570b51e1bf927b88368d8855d92b9833a24017a2bad4be
Run Code Online (Sandbox Code Playgroud)

但是,当我点击该链接时,我只看到页面:

Resend confirmation instructions
 Confirmation token is invalid
Run Code Online (Sandbox Code Playgroud)

我不做什么 - 我还需要设置什么.

CONFIRMATIONCONTROLLER:

def resource_params
 params.require(:user).permit(:confirmation_token)
   end
   private :resource_params


  def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])

if resource.errors.empty?
  set_flash_message(:notice, :confirmed) if is_navigational_format?
  sign_in(resource_name, resource)
  session['new_user'] = true
  respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else
  respond_with_navigational(resource.errors, …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise

8
推荐指数
2
解决办法
7633
查看次数

Rails正则表达式警告:字符类有' - '没有转义

我对regex soo了解不多,我只是找到一些并尝试使用它.

为什么我这个正则表达式有这个错误:

warning: character class has '-' without escape: /[a-zA-Z0-9-._ ]/
Run Code Online (Sandbox Code Playgroud)

这有什么不对?

验证应该只有字母,数字和" - ","." , "_", " " (空格处)

regex ruby-on-rails

8
推荐指数
1
解决办法
4230
查看次数

Rails 7.0.4 和 link_to 的数据确认不起作用

我最后的机会是 RoR 中最后一个活着的开发人员

互联网最黑暗的角落里的任何东西都不起作用:

<%= link_to 'some-link', '#', data: { confirm:'Are You Sure?') %>;
Run Code Online (Sandbox Code Playgroud)

它生成这个:

<a data-confirm="Are you sure?" href="#">some link</a>
Run Code Online (Sandbox Code Playgroud)

但没有确认对话框。

我尝试了一切 - Turbo_confirm,尝试添加带有刺激类的控制器......但仍然一无所获。

现在我移除了涡轮导轨、刺激装置等——但仍然一无所获。

ruby-on-rails ruby-on-rails-7

7
推荐指数
1
解决办法
1699
查看次数

铁轨4的弃用数量

a = Session.where(:date_at => date_from..date_to).
            order("date_at").
            count("DISTINCT(user_id)",
                  :group => "date(convert_tz(date_at, 'UTC', 'Europe/Warsaw'))")
Run Code Online (Sandbox Code Playgroud)

我怎么能在Rails 4中写这个?

这会产生错误:

DEPRECATION WARNING: Relation#calculate with finder options is deprecated. Please build a scope and then call calculate on it instead. (called from block (2 levels) in <top (required)> at /Users/xxx/Desktop/DEPLOY/d1_mysql/d1/app/admin/user.rb:11)
DEPRECATION WARNING: The :distinct option for `Relation#count` is deprecated. Please use `Relation#distinct` instead. (eg. `relation.distinct.count`). (called from block (2 levels) in <top (required)> at /Users/xxx/Desktop/DEPLOY/d1_mysql/d1/app/admin/user.rb:11)
Run Code Online (Sandbox Code Playgroud)

sql ruby-on-rails

6
推荐指数
1
解决办法
3691
查看次数

Facebook 无法获得电子邮件和 public_profile 的权限

我创建了新的应用程序,我想使用 oauth 通过 Facebook 在我的页面上登录。我的其他两个应用程序工作正常,但在这个新应用程序中我看到:

Your app has standard access to public_profile. To use Facebook Login, switch 
public_profile to advanced access. Get Advanced Access
Run Code Online (Sandbox Code Playgroud)

在电子邮件和 public_profile 字段旁边的 facebook 登录设置中,即使对于标准权限,它也显示“需要验证” ......

有人知道发生了什么事吗?

回答:

Facebook 现在似乎要求进行业务验证才能让“facebook 登录”起作用。上传公司文件两天后,Facebook 登录开始工作。

ruby-on-rails facebook-graph-api facebook-login

6
推荐指数
0
解决办法
1275
查看次数

Rails 6.1.4 - Ruby 3.0.1 - ActiveStorage 和 WebP 图像格式

没有关于如何设置 Rails 以使用 ActiveStorage 提供 WebP 图像的良好信息。

有人可以解释一下该怎么做吗?

我尝试:

应用程序.rb

config.active_storage.web_image_content_types = %w(image/jpeg image/png image/webp 
image/jpg)
Run Code Online (Sandbox Code Playgroud)

并在视图中:

<% image_tag( f.image_1.variant(resize_to_limit: [800,600], format: :webp) ) %>
Run Code Online (Sandbox Code Playgroud)

但这适用于开发(我看到 jpeg 的链接,但是当我使用鼠标右键并且“将图像另存为”时,图像将保存为 .WebP

在生产中,我没有看到浏览器的图像默认图标和 .jpg 链接

罗尔死了……

ruby ruby-on-rails webp rails-activestorage ruby-on-rails-6

5
推荐指数
1
解决办法
1659
查看次数

捆绑安装错误

当我移动我的网站做服务器并尝试捆绑安装时,我有这个错误.那意味着什么?我该做什么?

Git error: command `git reset --hard a9949c1524205928b18597f840e83478ba97c2ef` in directory
/usr/local/rvm/gems/ruby-1.9.3-p448/bundler/gems/active_admin-a9949c152420 has failed.
If this error persists you could try removing the cache directory
'/usr/local/rvm/gems/ruby-1.9.3-p448/cache/bundler/git/active_admin-    d67faab65e9b74efbc8efb4a777a851e9f78b2ca'
Run Code Online (Sandbox Code Playgroud)

而下一个错误:

fatal: ambiguous argument 'rails4': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
Git error: command `git rev-parse rails4` in directory
/usr/local/rvm/gems/ruby-1.9.3-p448/cache/bundler/git/friendly_id-     b6cdf0f76c0a31f3c34bb36c76f8ce70e1d6196b has failed.
Run Code Online (Sandbox Code Playgroud)

bundle ruby-on-rails

3
推荐指数
1
解决办法
5949
查看次数