目前,当我运行时,路由例外仍会显示rake routes.
resources :userhome, :except => [:new, :create, :edit, :update, :show, :destroy] do
collection do
post :create_invitation
end
member do
get :edit_profile_picture
post :update_profile_picture
end
end
Run Code Online (Sandbox Code Playgroud)
如何使例外工作?
当答案更新时,我试图在答案模型中验证分数是否大于零.这是我到目前为止所拥有的.
validates :score, :greater_than => 0, :on => :update
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误:
Unknown validator: 'greater_than'
Run Code Online (Sandbox Code Playgroud)
我在这里找到了more_than验证器.谢谢你的帮助.
我在开发环境中使用'Thin'作为我的rails服务器.我注意到一些令我惊恐的事情.我休息了一下......我的机器上没有按键.瘦机运行的终端窗口产生以下结果:
Started GET "/controller/method" for 127.0.0.1 at ...
Processing by ...Controller#method as HTML
Completed 401 Unauthorized in 58ms
Started GET "/users/sign_in" for 127.0.0.1 at 2013-08-16 11:47:02 -0400
Processing by Devise::SessionsController#new as HTML
...
Completed 200 OK in 178ms (Views: 22.3ms | ActiveRecord: 3.7ms)
Run Code Online (Sandbox Code Playgroud)
某处我的开发机器响应了对需要授权的特定页面的请求,并向某人显示了登录屏幕.它不在我的机器上.我办公室里没有其他人具备在我的机器上进行黑客攻击的技术能力或兴趣.所以它必须来自我的无线路由器或通过我们的互联网连接...我猜.
在生产中我有一个访问日志,它为访问我们网站的所有人提供了一个IP地址.我可以做些什么来提供这种信息吗?我可以在rails配置中做些什么来确认它确实是一次黑客攻击?
我在这里解决rails过程.如果有一个StackExchange站点来解决与我的路由器,互联网连接和开发机器相关的安全问题?它可能是哪一个?
谢谢.
在我的rails 2.3.8应用程序在Windows 7中运行,尝试启动服务器时出现以下错误:
D:\app1>ruby script/server
C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- active_support/core_ext (LoadError)
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from D:/app1/vendor/rails/activesupport/lib/active_support.rb:56
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from D:/app1/vendor/rails/railties/lib/commands/server.rb:1
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
Run Code Online (Sandbox Code Playgroud)
在下面的自定义需求文件块中...第36行是"gem_original_require path"
def require(path) # :doc:
gem_original_require path
rescue LoadError => load_error
if load_error.message =~ /#{Regexp.escape path}\z/ and
spec = Gem.searcher.find(path) then
Gem.activate(spec.name, "= #{spec.version}")
gem_original_require path
else
raise load_error
end
end
Run Code Online (Sandbox Code Playgroud)
宝石清单如下:
actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activeresource (2.3.8)
activesupport (2.3.8)
builder …Run Code Online (Sandbox Code Playgroud) 有许多关于Devise的帖子以及缺乏"current_user"用于模型的可用性.在这里和其他地方发布了大量的工作.但是,我没有在任何帖子中找到"为什么"的答案.这是安全问题吗?如果没有,为什么?
我在应用程序控制器中使用"检查授权",因此每个操作都需要权限.我开始给我,superadmin:=],管理所有权限.我认为管理所有会让我访问整个应用程序而无需命名资源.
用户模型:
def role?(role)
roles.include? role.to_s
end
Run Code Online (Sandbox Code Playgroud)
应用控制器:
check_authorization
Run Code Online (Sandbox Code Playgroud)
康康的能力模型:
def initialize(user)
if user.role? :superadmin
can :manage, :all
end
end
Run Code Online (Sandbox Code Playgroud)
错误信息:
This action failed the check_authorization because it does not authorize_resource. Add skip_authorization_check to bypass this check.
Run Code Online (Sandbox Code Playgroud)
谢谢.
我最近将此应用程序从rails 2.2.2更新到2.3.11.在升级之前,一切都运行良好.升级后,我收到以下错误:
ActiveRecord::HasAndBelongsToManyAssociationForeignKeyNeeded in InstrumentsController#arrow
Cannot create self referential has_and_belongs_to_many association on 'Trait#traits'. :association_foreign_key cannot be the same as the :foreign_key.
Run Code Online (Sandbox Code Playgroud)
在礼物模型:
class Gift < ActiveRecord::Base
has_many :delegate_gifts
has_many :answers
belongs_to :feel_motive, :class_name => "Trait", :foreign_key => "feel_motive_id"
belongs_to :see_motive, :class_name => "Trait", :foreign_key => "see_motive_id"
belongs_to :incline_motive, :class_name => "Trait", :foreign_key => "incline_motive_id"
has_and_belongs_to_many :users
has_and_belongs_to_many :best_contributions
def traits
traits = []
traits << feel_motive unless feel_motive.nil?
traits << see_motive unless see_motive.nil?
traits << incline_motive unless incline_motive.nil?
return traits …Run Code Online (Sandbox Code Playgroud) 由于IMGKit的代码示例不多,我在下面发布了我的代码示例.
我研究过IMGKit文档,说明你可以通过元标记将选项传递给wkhtmltoimage.所以我创建了一个包含以下元标记的页面:
<!DOCTYPE html>
<html>
<head>
...
<meta name="imgkit-height" content="420" />
...
</head>
<body>
...
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我正在使用Devise进行身份验证.它的变量"current_user"在应用程序中广泛使用,没有任何问题.然后我在名为"Answer"的模型中添加了以下范围
scope :user_answers, where (:user_id => current_user.id)
Run Code Online (Sandbox Code Playgroud)
此范围的结果是名为"问题"的模型中另一个范围的一部分
scope :qs_w_user_ans, joins(:questions) & Answer.user_answers
Run Code Online (Sandbox Code Playgroud)
从那时起,我收到以下错误:
undefined local variable or method `current_user'
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
谢谢.
更新:我正在更新问题以反映完整的解决方案.使用下面提到的time_diff gem Brett,以下代码有效.
码:
cur_time = Time.now.strftime('%Y-%m-%d %H:%M')
Time.diff(Time.parse('2011-08-12 09:00'), Time.parse(cur_time))
Run Code Online (Sandbox Code Playgroud)
谢谢,布雷特.
我的控制器中的这一行:
@feedback = Feedback.where("reviewer_id = ?, reviewee_id = ?, strength_id = ?", current_user.id, @report_for.id, @context ).first
Run Code Online (Sandbox Code Playgroud)
当我尝试显示时产生此错误@feedback.something:
Mysql2::Error: Operand should contain 1 column(s): SELECT `feedbacks`.* FROM `feedbacks` WHERE (reviewer_id = 1, reviewee_id = 10, strength_id = 0) LIMIT 1
Run Code Online (Sandbox Code Playgroud) 在rails 3.0.8中,一切都运行良好.我升级到3.2轨,但最终得到的东西准备瑞恩·贝茨在Railscast建议先升级到最新的3.0的轨道版本是3.0.17.升级到3.0.17后我得到了:
undefined method `reputation_value_for'
Run Code Online (Sandbox Code Playgroud)
我在rvm安装Ruby版本1.9.2中运行rails.为了确保它不是宝石的问题,我卸载1.9.2并重新安装它.我安装了bundler gem,然后运行了bundle install.它仍然有同样的错误.
然后我重命名了数据库迁移并运行了rails g Reputation_system.旧的和新的迁移文件完全相同.
这里有完整的回溯,Gemfile和Gemfile.lock的要点.
在我的控制器中,一大堆数字被碾压.百分比乘以100,因此可以将它们存储为整数.
tot = @mot[1] + @mot[2] + @mot[3]
exec_pct = @mot[3] / tot * 100
tact_pct = @mot[2] / tot * 100
strat_pct = @mot[1] / tot * 100
Run Code Online (Sandbox Code Playgroud)
然后应该将值写入用户记录,如下所示:
@user = User.where(id = current_user.id)
@user.update_attributes(:strat_pct => strat_pct.to_i, :tact_pct => tact_pct.to_i, :exec_pct => exec_pct.to_i )
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
undefined method `update_attributes'
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.