我正在关注Hartl的railstutorial.org并且已经到了11.4.4:生产中的图像上传.我做了什么:
权限: 本教程指示"授予对上一步中创建的用户的读写权限".但是,在存储桶的"Permissons"下,未提及新用户的名称.我只能选择Everyone,Authenticated用户,Log delivery,Me和用户名,亚马逊似乎已经从我的名字+数字创建了自己.我通过选择Authenticated用户并选中上传/删除和查看权限(而不是选择列表和编辑权限)框来尝试它.我也通过选择Everyone并检查所有四个框来尝试它.结果是一样的.
初始化carrier_wave.rb程序设置为以下代码.我已经添加region: 'eu-west-1'到初始化器(我从这里得到的一个想法)去除消息connecting to the matching region will be more performant.
if Rails.env.production?
CarrierWave.configure do |config|
config.fog_credentials = {
# Configuration for Amazon S3
:provider => 'AWS',
:aws_access_key_id => ENV['S3_ACCESS_KEY'], # Set these key's using heroku config:set S3_ACCESS_KEY=<access key>
:aws_secret_access_key => ENV['S3_SECRET_KEY'],
:region => 'eu-west-1'
}
config.fog_directory = ENV['S3_BUCKET']
end
end
Run Code Online (Sandbox Code Playgroud)
错误:
在生产中使用上传器上传图像时,我收到错误We're sorry, but …
ruby ruby-on-rails amazon-s3 amazon-web-services railstutorial.org
我知道这个问题已经被问过很多次了,但不知何故它对我不起作用。我希望用户在登录后重定向到特定页面(使用 Devise)。我正在使用 Rails 3.2 和 Ruby 4。
因为用户会被重定向到: - 登录后,如果用户从根路径所属的控制器控制的页面之一进入登录页面,则登录后,他们会被重定向到根。这些页面不需要授权。- 登录后,如果用户通过单击需要授权的页面自动进入登录页面,他们将被重定向到请求的页面。
要在登录后将用户重定向到特定页面,我知道您需要向控制器添加一些行。对于控制需要授权的页面的控制器,我添加了:
class AccountsController < ApplicationController
before_filter :authenticate_user!
def user1_home
end
def user2_home
end
def user3_home
end
protected
def after_sign_in_path_for(resource)
'accounts/user1_home'
end
end
Run Code Online (Sandbox Code Playgroud)
然而,这并没有改变任何事情。我也尝试过def after_sign_in_path_for(resource) 'accounts#user1_home_path' end
我是否还应该更改routes.rb 中的某些内容?我的路线是:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration …Run Code Online (Sandbox Code Playgroud) 我对这一切都很陌生但是能够在我的Rails应用程序中使用头像/图像上传器.用户可以将新的头像上传到我的S3存储桶,并且在web应用程序中显示头像.
为此,我不得不向用户授予"AmazonS3FullAccess"政策.这看起来有点太多了,因为来自应用程序的用户只需要写入(上传他的头像)并阅读(在网页上显示头像)权限.
您是否同意编写自定义策略而不是使用AmazonS3FullAccess更好?如果是这样,我已经尝试了下面的政策代码(从这里采用),但这不起作用(尝试上传头像图像时出现403 Forbidden错误).有任何建议如何更正此代码?
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:ListBucket"],
"Resource": ["arn:aws:s3:::mybucket"]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": ["arn:aws:s3:::mybucket/*"]
}
]
}
Run Code Online (Sandbox Code Playgroud) cloud ruby-on-rails amazon-s3 amazon-web-services amazon-iam
我正在尝试为我的 Rails 应用程序构建 JSON API,并编写了以下方法:
def create
organization = Organization.find(params[:organization][:node_id])
node = organization.nodes.build(nodes_params.except[:id])
if node.save
render json: node, status: :ok
else
render json: node, status: :bad_request
end
end
Run Code Online (Sandbox Code Playgroud)
在 Postman 中尝试该方法会返回错误:“无法验证 CSRF 令牌的真实性”。基于这篇文章,我将下面的代码添加到基本控制器中。不幸的是,这没有什么区别。有人了解错误的原因吗?
protect_from_forgery
skip_before_action :verify_authenticity_token, if: :json_request?
private
def json_request?
request.format.json?
end
Run Code Online (Sandbox Code Playgroud) 远程我有几个分支,例如 master、12.0 和 13.0。13.0 领先于 12.0,12.0 再次领先于 master。
本地我只有分支 13.0,它与远程分支是最新的。
现在我也想在本地拥有 12.0 分支。所以我进入git checkout -b 12.0然后git pull origin 12.0。但是,第一个命令基于 13.0 创建本地分支 12.0,因此git pull会产生错误。
那么如何在本地计算机上获取远程 12.0 分支呢?
我正在尝试实施Carrierwave 删除上传的文件.虽然上传本身可以正常工作,但删除图像/徽标不起作用.正如Carrierwave建议我在视图中添加一个复选框以删除上传的徽标.所以我在我的视图页面中:
<div class="logo">
<%= f.label :logo %>
<%= f.file_field :logo, accept: 'image/jpeg,image/gif,image/png', style: "width:100%" %>
<p>
<label>
<%= f.check_box :remove_logo %>
Remove logo
</label>
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我想通过添加此复选框,删除徽标现在已经可以使用了.但是,选中该框然后提交表单不会删除徽标(它也不会生成错误消息).服务器说:
Started PATCH "/users/fakename11"
Processing by UsersController#update as HTML
Parameters: {"utf8"=>"?", "authenticity_token"=>"eR3XCiW***Oge0w==", "user"=>{"fullname"=>"Natasha Pacocha", "email"=>"example@example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "remove_logo"=>"1", "organization"=>"Bartoletti-Bins", ...etc...}, "commit"=>"Save changes", "id"=>"fakename11"}
Unpermitted parameter: remove_logo
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么做unpermitted parameter.我已经尝试添加attr_accessor :remove_logo到控制器以及用户模型,但这没有任何区别.
宝石也谈到@user.remove_logo!和@user.save.所以我尝试在控制器的update方法中添加它们,如下所示.但这没有任何区别.我究竟做错了什么?
def update
@user = User.friendly.find(params[:id])
if @user.update_attributes(update_params)
if params[:remove_logo]
@user.remove_logo!
@user.save
end
flash[:success] = …Run Code Online (Sandbox Code Playgroud) 我曾经能够毫无问题地推向Heroku.在做了一些似乎与我的问题无关的更改后,它无法推送到Heroku.在git push heroku我得到的错误:
...
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: rake aborted!
remote: Sprockets::FileNotFound: could not find file: /tmp/build_c657fd7***e8c75a3/app/assets/stylesheets/application.css
remote: /tmp/build_790d1e***cab4395/vendor/bundle/ruby/2.2.0/gems/sprockets-3.3.3/lib/sprockets/loader.rb:103:in `load_from_unloaded'
remote: /tmp/build_790d1***ab4395/vendor/bundle/ruby/2.2.0/gems/sprockets-3.3.3/lib/sprockets/loader.rb:60:in `block in load'
...
remote: ! Precompiling assets failed.
remote: ! Push rejected, failed to compile Ruby app
remote: ! Push rejected to ***.
Run Code Online (Sandbox Code Playgroud)
application.css 确实存在于我的开发环境中,包括:
*= require_self
*= require universal
*= require bootstrap-datepicker3
*= require menu_header
*= require table
*= require wice_grid
*= require_tree .
Run Code Online (Sandbox Code Playgroud)
有没有人知道可能导致问题的原因以及该怎么办?如果我可以通过重置某些东西来解决它,那么这是一个选项,因为应用程序尚未生效,因此不存在丢失数据的风险.
我想测试一下flash消息是否包含某些文本.所以我有这条线:
assert_select flash[:info], "Your fee is valid till"
Run Code Online (Sandbox Code Playgroud)
然而,这失败并显示错误消息:
DEPRECATION WARNING: The assertion was not run because of an invalid css selector.
unexpected '#' after ''
Run Code Online (Sandbox Code Playgroud)
有谁知道我做错了什么?
ruby testing integration-testing ruby-on-rails ruby-on-rails-4
我是 NodeJS 新手,尝试在 Cloud9 IDE 中设置一个现有项目(由其他人开发)(我使用的是较旧的 Cloud9 帐户;因此不在 AWS 上运行)。我已经拉取了 git 并安装了所有东西。这一切似乎都没有问题。
\n要在 Cloud9 之外本地运行该应用程序,您可以启动服务器npm run start(我从开发该应用程序的人那里知道,这对他有用)。但我想在Cloud9中设置它,并且在Cloud9中需要先设置一些变量(如果我不先定义主机,则会给出错误“无效的主机头”)。因此,我使用以下两个命令:
export HOST=$C9_HOSTNAME && export PORT=8080\nnpm run start\nRun Code Online (Sandbox Code Playgroud)\n产生npm run start错误:
\n\n无法在 appname-username.c9users.io 找到开放端口。
\n网络错误消息:listen EADDRNOTAVAIL 35.189.252.103
\n
考虑到https://docs.c9.io/docs/run-an-application,我相信我的端口是正确的。我\xe2\x80\x99ve也尝试了值8081、8082和$PORT,但这些都不起作用。
\n有什么想法可以让 Cloud9 本地预览正常运行吗?
\n根据要求,一些线路来自start.js:
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;\nconst HOST = process.env.HOST || \'0.0.0.0\';\nconsole.log(`1. The host is ${HOST} on port ${DEFAULT_PORT}`); //ADDED\n\nchoosePort(HOST, DEFAULT_PORT)\n .then(port => …Run Code Online (Sandbox Code Playgroud) 在我的整个应用程序中,我使用起来i18n没有问题。但是,对于通过 cron 作业发送电子邮件,我收到错误:
引用错误:__ 未定义
在app.js我配置 i18n 中:
const i18n = require("i18n");
i18n.configure({
locales: ["en"],
register: global,
directory: path.join(__dirname, "locales"),
defaultLocale: "en",
objectNotation: true,
updateFiles: false,
});
app.use(i18n.init);
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我将其用作__('authentication.flashes.not-logged-in'),就像我说的那样,没有任何问题。在由 cron 作业调用的邮件控制器中,我以相同的方式使用它:__('mailers.buttons.upgrade-now')。然而,只有在那里,它才会产生上述错误。
只是为了尝试,我已在邮件控制器中将其更改为i18n.__('authentication.flashes.not-logged-in'). 但后来我收到另一个错误:
(node:11058) UnhandledPromiseRejectionWarning: TypeError: logWarnFn is not a function
at logWarn (/data/web/my_app/node_modules/i18n/i18n.js:1180:5)
Run Code Online (Sandbox Code Playgroud)
知道如何使通过 cron 作业发送的电子邮件正常工作吗?