我在 Windows 8.1 机器上安装 mysql2 gem 时遇到了一些问题。我按照这篇文章中的说明进行操作:
安装mysql2gem,我没有收到任何错误消息。
我跟着这个
bundle install
Run Code Online (Sandbox Code Playgroud)
命令,并确认安装了以下 gems(使用 bundle show),确认我安装了以下 gems:
Using devise (3.2.2)
Using mysql2 (0.3.14)
Run Code Online (Sandbox Code Playgroud)
然后我尝试这样做:
rails generate devise:install
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/lib/mysql2.rb:8:in `require': 126: The specified module could not be found.
- C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/lib/mysql2/mysql2.so (LoadError)
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/lib/mysql2.rb:8:in `<top (required)>'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:76:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:72:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:72:in `block in require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:61:in `each'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:61:in `require'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler.rb:131:in `require' …Run Code Online (Sandbox Code Playgroud) Rails 4.1 Ruby 2.0 Windows 8.1
我找到了number_to_currency助手,但没有找到currency_to_number.我试图将$ 8,000之类的东西转换为小数.那有没有Rails助手?有任何想法吗?
我一直在用这个:
number.to_s.gsub(/[^\d\.]/, '').to_f
Run Code Online (Sandbox Code Playgroud)
除了数字和小数点之外,它还消除了所有内容,并且还处理了意外整数.我想知道我是否错过了某种currency_to_number助手.看起来我不是.我会接受其中一个答案.
OS: Ubuntu 16.01
PHP: 7/0
Run Code Online (Sandbox Code Playgroud)
根据一些谷歌搜索以及 StackOverflow 上问题的输入,我设置以下 Curl 选项:
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_CAINFO = '/etc/ssl/certs',
Run Code Online (Sandbox Code Playgroud)
我验证了 /etc/ssl/certs 目录是否存在,并且是最新的。
我还修改了文件/etc/php/7.0/cli/php/ini:
openssl.capath='/etc/ssl/certs'
Run Code Online (Sandbox Code Playgroud)
当我尝试进行 Curl 调用时,出现以下错误:
[error] => error setting certificate verify locations:
CAfile: /etc/ssl/certs
CApath: /etc/ssl/certs
Run Code Online (Sandbox Code Playgroud)
我将 /etc/ssl/certs 中的权限编辑为:
rwxr-xr-x
Run Code Online (Sandbox Code Playgroud)
但我遇到了同样的错误。
有任何想法吗?
我有一个使用Devise设置的Rails应用程序,带有注册控制器.
到目前为止有什么工作:
新用户注册登录注销主页关于确认密码重置
不工作是编辑,因为我无法弄清楚我应该进行的URL/REST调用以显示编辑.我有一个views/registrations/edit.html.erb页面.
以下是我的路线中特定于注册的部分:
cancel_user_registration GET /cancel(.:format) registrations#cancel
user_registration POST / registrations#create
new_user_registration GET /request_invite(.:format) registrations#new
edit_user_registration GET /edit(.:format) registrations#edit
Run Code Online (Sandbox Code Playgroud)
以下是我的routes.rb中特定于设计的部分:
devise_for :users, :controllers => { :registrations => 'registrations', :confirmations => 'confirmations' }, :path => '', :path_names => { :sign_in => "login", :sign_up => "request_invite" }
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
http://localhost:3000/edit
http://localhost:3000/edit/:id
http://localhost:3000/registrations/:id/edit
http://localhost:3000/user/:id/edit
Run Code Online (Sandbox Code Playgroud)
我明白了:没有路线匹配[GET] ......
StackOverfloww上有几个有用的问答环节,但我无法弄清楚如何在这里为我提供建议.有任何想法吗?
我按照我在stackOverflow上找到的建议,并将以下内容添加到layouts/application.html.erb的部分:
<%= favicon_link_tag '/favicon.ico' %>
Run Code Online (Sandbox Code Playgroud)
favicon.ico在我的公共文件夹中我也试图将它放在assets/images文件夹中
我重新启动了rails服务器(MAC上的本地开发环境,Rails 3.2.xxx),但我没有看到favicon.有任何想法吗?
我的Gemfile中有什么
gem'rake','10 .0.3'#gemfile中的第一行
删除了Gemfile.lock
运行Bundle更新
Ran bundle update rake
运行资产:预编译
我收到以下消息:
You have already activated rake 10.0.4, but your Gemfile requires rake 10.0.3.
Run Code Online (Sandbox Code Playgroud)
捆绑显示输出:
捆绑包含的宝石:
....
* rake (10.0.3)
Run Code Online (Sandbox Code Playgroud)
任何想法为什么我收到此错误消息(我遵循的程序是Stackoverflow的建议摘要)?
Rails 4.1
Ruby 2.0
Windows 8.1
Run Code Online (Sandbox Code Playgroud)
在我的助手/ application_helper.rb中,我有:
def agents_and_ids_generator
agents = Agent.all.order(:last)
if agents
agents_and_ids = [['','']]
agents.each do |l|
name = "#{l.first} #{l.last}"
agents_and_ids << [name,l.id]
end
return agents_and_ids
end
end
Run Code Online (Sandbox Code Playgroud)
在我的views/agents/form.html.erb中,我有以下内容:
<%= f.select :agent_id, options_for_select(agents_and_ids_generator) %>
Run Code Online (Sandbox Code Playgroud)
在我的controllers/agents_controller.rb中,我有以下内容:
include ApplicationHelper
Run Code Online (Sandbox Code Playgroud)
但是当我转到此视图时,我收到以下错误消息:
未定义的局部变量或方法`agents_and_ids_generator'用于#<#:0x00000006fc9148>
如果我将agents_and_ids_generator方法移动到helpers/agents_helper.rb,它可以正常工作.
我认为通过将方法放在应用程序帮助器中并将应用程序包含在控制器中,这些方法可用于视图.这个假设我不正确吗?
确保应用程序帮助程序未包含在控制器中,并添加了以下简化:
<%= f.collection_select :agent_id, Agent.all.order(:last), :id, :name_with_initial, prompt: true %>
#app/models/agent.rb
Class Agent < ActiveRecord::Base
def name_with_initial
"#{self.first} #{self.last}"
end
end
Run Code Online (Sandbox Code Playgroud) 更多新手问题.
我知道如果我在我的应用程序助手中定义一个方法,它可用于整个应用程序代码.
在我的应用助手中,我有:
def primary_user_is_admin
if current_user
user_login_roles = JSON.parse(current_user.role)
if user_login_roles["admin"]
return 1
end
end
return nil
end
Run Code Online (Sandbox Code Playgroud)
如果我从categories_controller调用它:
if !primary_user_is_admin
redirect_to root_url
end
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:未定义的局部变量或方法`primary_user_is_admin'
如果我将primary_user_is_admin代码放在registrations_helper.rb文件中,也会发生这种情况
但是,如果我在任何视图中使用它(例如views/user/edit.html.erb)
<% if primary_user_is_admin %>
<% end >
Run Code Online (Sandbox Code Playgroud)
然后它工作.我错过了什么?
环境:MAC - Mountain Lion我正在尝试将AWS PHP SDK用于项目.我按照亚马逊网站的SDK安装说明(通过作曲家) - 使用以下链接到AWS
我创建了文件compser.json.含量研究:
{
"require": {
"aws/aws-sdk-php": "2.*"
}
}
Run Code Online (Sandbox Code Playgroud)
从命令行,我输入:
curl -s "http://getcomposer.org/installer" | php
Run Code Online (Sandbox Code Playgroud)
然后
php composer.phar install
Run Code Online (Sandbox Code Playgroud)
新目录显示为"vendor",在其中,AWS SDK 2自动安装.
问题是我期待(根据我试图遵循的代码示例),我期待看到以下文件:
vendor/aws/aws-sdk-for-php/sdk.class.php
Run Code Online (Sandbox Code Playgroud)
但它不在那里.这可能是引用旧版本的SDK吗?
由"php composer.phar install"命令自动生成:vendor/autoload.php如下所示:
<?php
// autoload.php generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit25a7292f83dd9a43a459f6c2e51befba::getLoader();
Run Code Online (Sandbox Code Playgroud)
是否有可能文件:sdk.class.php对SDK的版本1有效,但对版本2无效?
我正在将设计与我的 Rails 3 应用程序一起使用。当前重置密码的行为是单击“忘记密码?” 关联。这里的链接是:
(url)/password/new.user
Run Code Online (Sandbox Code Playgroud)
这将在设计 passwords_controller.rb 中调用以下方法:
def new
build_resource({})
end
Run Code Online (Sandbox Code Playgroud)
此方法将执行以下操作:
生成密码重置令牌并将其添加到数据库中,
向此人发送一封电子邮件,其中包含包含令牌的链接:
(url)/password/edit?reset_password_token=xxxxxxxxxxxxxxx
有什么方法可以说服 Devise 只执行第 1 步而不是第 2 步吗?如果可能的话,是否有任何安全问题我应该注意,我确实采用了这种方法来简化网站的一部分。