Tag: 动作控制器

如何使用与我没有保存到数据库的对象相关的数据?

我需要使用他在表单中输入的用户数据,但不保存它。 我在我的User模型中添加了属性访问器: attr_accessible :paypal_email, :first_name, :last_name attr_accessor :first_name attr_accessor :last_name 但是如何在用户提交表单后使用它呢? 我需要validation帐户详细信息,但没有保存,所以我需要在控制器中使用 @user.first_name and @user.last_name 我的validation操作: def verify @user = User.find(params[:user_id]) require ‘httpclient’ require ‘xmlsimple’ clnt = HTTPClient.new header = {“X-PAYPAL-SECURITY-USERID” => “№№№№№№№№”, “X-PAYPAL-SECURITY-PASSWORD” => “333333333”, “X-PAYPAL-SECURITY-SIGNATURE” => “3333333333”, “X-PAYPAL-REQUEST-DATA-FORMAT” => “NV”, “X-PAYPAL-RESPONSE-DATA-FORMAT” => “XML”, “X-PAYPAL-APPLICATION-ID” => “APP-2J632856DC989803F” } data = {“emailAddress” => @user.paypal_email, “firstName”=> […]

ActionController ::与SSE一起生效无法正常工作

我正在尝试在一个项目中使用Rails 4.0.1中的直播,但我发现问题…… 我有这个动作: def realtime_push response.headers[‘Content-Type’] = ‘text/event-stream’ sse = SSE.new(response.stream) d = Domain.find(params[:domain_id]) begin loop do backlinks = d.backlinks.page(params[:page]).per(10) pagination = render_to_string(:partial => ‘backlinks/pagination’, :layout => false, :locals => { :backlinks => backlinks }) sse.write({ :html => pagination }, :event => ‘pagination’) sleep 1 end rescue IOError # When the client disconnects, we’ll get […]

如果before_action返回false,如何执行操作

我知道使用以下代码: before_action :signed_in?, only: [:new] 如果signed_in?将执行new动作signed_in? 返回true,但是如果我想在signed_in?时执行new操作signed_in? 返回false我该怎么办? 我是否必须创建一个名为not_signed_in?的新方法not_signed_in? ? 这是我的signed_in? 方法 def signed_in? !@current_user.nil? end

如何让ActionController :: Live流与Thin一起使用?

题 你可以使用ActionController::Live thin实现服务器端事件(SSE)和长轮询吗? 如果是这样,怎么样? 上下文 虽然标题是如何获取Rails 4 ActionController :: Live流与Thin和Ruby 2一起使用的重复? Thin和Puma如何通过直播流扩展? OP通过提出两个问题来混淆水域,这个问题从来没有得到解答。 许多其他post建议你可以使用thin服务器端事件(sse),如果你通过exec thin start –threaded启动它exec thin start –threaded : Heroku是否支持ActionController :: Live? 和puma只有multithreading导轨4 http服务器? ,Aaron的开创性的http://tenderlovemaking.com/2012/07/30/is-it-live.html和Ryan的常年可靠的http://railscasts.com/episodes/401-actioncontroller-live?view=asciicast 。 但即使我正在复制Railscast示例,我还是无法让它与thin一起工作。 我试过的 # —————————————————————- # file: config/routes.rb Rails.application.routes.draw do resources :widgets do collection do get ‘events’ # SSE test end end end _ # —————————————————————- # file: […]