你如何阻止其他用户编辑一个对象,比如一个不属于他们自己的个人资料对象呢?
大多数在线示例都是具有多个用户角色的复合体,我无法使其工作,但必须简单:
def initialize(user)
can :update, Profile do |profile|
profile.try(:user) == current_user
end
end
Run Code Online (Sandbox Code Playgroud)
在我的ProfilesController#edit中
authorize! :update, @profile
Run Code Online (Sandbox Code Playgroud) 我想包含一些不在资产管道中的js文件,我尝试将它们包含在rails.root和这些文件的完整路径中,但这不是许可的工作原因。
我知道我可以在资产管道JS application.js中手动包括每个单独的JS文件,但这会做很多工作,因为我的JS在开发过程中发生了很多变化,因此,如果有一种方法可以包括js文件,那就太好了外部资产管道。
有人对我该如何处理有一些建议吗?
升级到rails 3.2并设计2.0并单击通过电子邮件发送的确认链接或从开发中的控制台复制后,confirmed_at列不会更新.结果就是你无法登录.
解决这个问题的方法是什么,因为日志中没有任何内容,可访问的属性包含了confirmed_at,因此该列应该是可更新的.
我遵循了关于禁用活动记录的SQL查询日志记录的所有主题.谁知道如何在rails 3.2.x中正确禁用它?
有没有办法检测表单是否已提交?我试图基于自定义验证设置类,如下例所示,这可能吗?
.control-group{ :class => ("error" if form_is_submitted ) }
Run Code Online (Sandbox Code Playgroud)
现在尝试:
.control-group{ :class => ("error" if params[:user][:profile_attributes][:gender] == nil) }
Run Code Online (Sandbox Code Playgroud)
如果表单未提交,则会失败,因为params是nill并抛出错误
使用自定义故障类实现设计用于检测用户是否未确认的触发器是什么?warden_message不起作用.有谁知道?
class CustomFailure < Devise::FailureApp
def redirect_url
if warden_options[:scope] == :user
new_user_registration_path
else
new_user_registration_path
end
end
def respond
if http_auth?
http_auth
else
store_location!
flash[:alert] = i18n_message unless flash[:notice]
if warden_message == :unconfirmed
redirect_to "/confirm"
else
redirect_to sign_in_path
end
end
end
end
Run Code Online (Sandbox Code Playgroud) Devise支持可重新配置选项,当用户更改电子邮件时,他们必须确认新电子邮件.
但是,使用标准确认邮件模板.我想为必须重新确认的电子邮件使用单独的邮件模板.
devise的registrations_controller.rb:
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
if resource.update_with_password(resource_params)
if is_navigational_format?
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:update_needs_confirmation : :updated
set_flash_message :notice, flash_key
end
sign_in resource_name, resource, :bypass => true
respond_with resource, :location => after_update_path_for(resource)
else
clean_up_passwords resource
respond_with resource
end
end
Run Code Online (Sandbox Code Playgroud)
任何人都知道在哪里挂钩Devise让它使用单独的电子邮件文本来重新确认电子邮件,而不是使用默认的确认文本?
ruby-on-rails actionmailer confirmation devise ruby-on-rails-3
试图找出为什么我的nil检查在调用没有param的方法或者没有产生记录的param id时失败.
@game = Game.where(:id => params[:id]).first
if @game.nil?
redirect_to root_path
end
Run Code Online (Sandbox Code Playgroud)
在控制台中这很好用.
>> pp @game.nil?
=> true
Run Code Online (Sandbox Code Playgroud)
在应用程序中,这失败了(它永远不会重定向!),为什么?
在控制台中(param id为nil或不存在记录值):这有效:
unless Game.exists?(params[:id])
raise('ok')
end
Run Code Online (Sandbox Code Playgroud)
但不是在现实生活中的应用程序:(我几乎用各种方式检查记录是否存在或有效,代码只是通过此检查并继续原样
看看其他一些代码,我注意到我使用了一个返回语句,IT似乎用它解决了这个问题.
作品:
unless Game.exists?(params[:id])
redirect_to root_path
return
end
Run Code Online (Sandbox Code Playgroud)
失败:
unless Game.exists?(params[:id])
redirect_to root_path
end
Run Code Online (Sandbox Code Playgroud)
不太确定为什么它需要在redirect_to explicit之后返回
我的rspec路由规范给出了不清楚的错误.在预期的params v/s中,id param处于反向位置的真实参数.为什么以及如何解决?
require "spec_helper"
describe GameController do
describe "routing" do
game = FactoryGirl.create(:game)
it "routes to #show" do
get("/game/1").should route_to("game#show", :id => 1)
end
end
end
Run Code Online (Sandbox Code Playgroud)
抛出错误:
1) gameController routing routes to #show
Failure/Error: get("/game/1").should route_to("game#show", :id => 1)
The recognized options <{"action"=>"show", "controller"=>"game", "id"=>"1"}> did not match <{"id"=>1, "controller"=>"game", "action"=>"show"}>, difference:.
<{"id"=>1, "controller"=>"game", "action"=>"show"}> expected but was
<{"action"=>"show", "controller"=>"game", "id"=>"1"}>.
# ./spec/routing/game_routing_spec.rb:11:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud) 我使用载波将资产上传到我的应用程序,它们存储在/public/uploads/photos/file/user_id/user_id.jpg中以简化操作.
只有在制作中我才能获得所有这些图像的404.我尝试chmod 777上传-R*作为最后的手段,但这没有帮助.
我是否需要设置一些我在这里缺少的东西才能使它工作,因为这些资产不在资产管道之内?
devise ×4
actionmailer ×1
activerecord ×1
cancan ×1
carrierwave ×1
confirmation ×1
forms ×1
include ×1
logging ×1
redirect ×1
rspec ×1
specs ×1
sql ×1
submit ×1
upload ×1