我试图覆盖默认设计注册控制器的一些功能,以便只有某些用户可以为其他用户创建帐户.因此,在controllers/users文件夹下名为registrations_controller.rb的文件中,我有以下内容
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :check_permissions, :only => [:new, :create, :cancel]
skip_before_filter :require_no_authentication
def check_permissions
authorize! :create, resource
end
end
Run Code Online (Sandbox Code Playgroud)
在我的路线文件中我有
devise_for:users,:controllers => {:registrations =>'users/registrations'}
当我尝试转到users/sign_up url时,我得到一个路由错误'uninitialized constant Users :: RegistrationsController'.
所以真正让我了解的是,我在rails 3应用程序中使用了几乎完全相同的功能而没有任何问题.我看了一些类似于此的其他stackoveflow问题,我仍然没有更聪明.我现在正在构建的应用程序是rails 3.1应用程序,我正在使用设计1.5.1
以下是它们有用的相关路线
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"users/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"users/registrations"} …Run Code Online (Sandbox Code Playgroud) 我有一个简单的宁静服务,我正在用java开发.我一直在寻找编组/解组json的一些选项.可用的方法,jaxb jackson等,对我来说都是一个新手,我正试图找到他们的脚.我想知道我是否可以得到一些关于什么是最好的方法和技术的建议,特别是考虑到我感兴趣的许多对象已经实现为不可变并且我使用了构建器模式.所以没有setter,构造函数是私有的.
我看过上一个问题:Jackson + Builder Pattern?发布在stackoverflow上.我正在考虑类似这种方法的东西,尽管获得一些关于使用@JsonDeserialize的更多资源的指针会很棒
这是我正在考虑的对象类型的一个非常简单的例子
public class Reading {
private final double xCoord;
private final double yCoord;
private final double diameter;
private final double reliability;
private final String qualityCode;
private Reading(Builder builder){
xCoord = builder.xCoord;
yCoord = builder.yCoord;
diameter = builder.diameter;
reliability = builder.reliability;
qualityCode = builder.qualityCode;
}
public static class Builder {
//required parameters
private final double diameter;
//optional parameters
private double xCoord = 0.0;
private double yCoord = 0.0;
private double reliability = 1.0; …Run Code Online (Sandbox Code Playgroud) 我一直在使用rest-client访问我编写的rails应用程序.我写了一个快速脚本来登录并发布帖子请求.一切正常,但我必须解决这样一个事实,即如果你在json中请求表单,则不会提供authenticity_token.我不得不在其他地方做一个普通的html请求获取authenticity_token,然后将其包含在我作为帖子请求的一部分提交的json中.基本上我有一个快速的脏脚本,如下所示
private_resource = RestClient::Resource.new( 'https://mysite.com')
params = {:user => {:email => 'user@mysite.com', :password => 'please'}}
#log in
login_response = private_resource['users/sign_in'].post(params, :content_type => :json, :accept => :json)
#get cookie
cookie = login_response.cookies
#get json
json_response = private_resource['products/new'].get(:content_type => :json, :accept => :json, :cookies => cookie)
#another request that returns html form with authenticity token
response_with_token = private_resource['products/new'].get( :cookies => cookie)
#extract token
token = Nokogiri::XML(response_with_token).css('input[name=authenticity_token]').first.attr('value')
#update cookie
cookie = response_with_token.cookies
#populate form and insert token
form = JSON.parse(json_response)
form['name'] = "my …Run Code Online (Sandbox Code Playgroud) 我一直在研究如何使用PDFKit为我正在开发的Rail 3应用程序生成pdf报告.基本上,如果我使用PDFKit作为中间件,应用程序中的任何页面都很好地呈现为pdf,包括javascript生成的图形.
但是,我想为pdf报告使用不同的布局来删除任何侧边栏或导航细节,因此我没有使用中间件选项,而是将其添加到相关的控制器操作中
format.pdf {
html = render_to_string(:action => "show.html.erb", :layout => "report.html.erb")
kit = PDFKit.new(html)
kit.stylesheets << "#{Rails.root}/public/stylesheets/application.css"
send_data kit.to_pdf, :filename => "file.pdf", :type => :pdf}
Run Code Online (Sandbox Code Playgroud)
(我也尝试了将此功能提取到渲染器选项的neater选项,如Katz 在此描述但逻辑和问题是相同的)
这肯定解决了我的布局问题,但似乎没有应用程序的javascripts正在运行,图表不再出现.我看了一下PDFKit源代码,但我发现pdf的生成方式没有任何重大差异.
我仍然用铁轨找到很多东西,所以我敢肯定这可能是非常显而易见的盯着我的东西.任何人可能拥有的任何指针都将非常感激