actioncontroller

Call to expire_fragment raises “ to use #url_for, you must include routing helpers explicitly” error

笑着哭i 提交于 2019-12-12 15:39:21
问题 I've been upgrading a Rails 2 app to Rails 3.2.13 and am having a problems when I try to enable caching. Caching worked in Rails 2 and I'm using the same version of Ruby - 1.8.7. I'm not sure if it is relevant but I'm developing on OSX. The error's being thrown from the ActionController::Caching::Fragments class when expire_fragment is called. expire_fragment makes a call to fragment_cache_key which contains this: ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://

Rails “action” params key conflict

我们两清 提交于 2019-12-12 10:42:23
问题 I am building a RESTful Rails service with various CRUD endpoints. On one of the Create endpoints, the data I am passing in includes: ... action: "action_name" ... The problem I am having is that params[:action] contains "create", not the actual value of the action parameter I'm passing in. This, I assume, is because params[:action] is being populated by Rails automatically. Is there another way to access this key I am passing in? Am I doing something blatantly stupid? 回答1: Its awkward to use

set default_url_options on initialize

岁酱吖の 提交于 2019-12-10 17:00:08
问题 I need to force the host in one of the environments in my rails app. I've can get the override to work by including def default_url_options(opts={}) opts.merge({:host => 'stg.my-host.com'}) end in app/controllers/application.rb But is there a way to set this on initialize, preferably in a config/environments/... file? I'd like to keep conditional env logic out of the controller. But when I try config.action_controller.default_url_options = { ... } or even ActionController::Base.default_url

ActionController::UrlGenerationError in Valuations#new

我的梦境 提交于 2019-12-10 10:58:38
问题 I've read other SO articles relating to UrlGenerationError 's which seem to point to singularization or plurization of a word, but I don't think that's the issue here. It works when I remove from valuations/_form.html.erb: <%= render "comments/comments" %> <%= render "comments/form" %> Submit the _form with :name & :tag_list , readd <%= render "comments/comments" %> <%= render "comments/form" %> and then refresh. What's the deal when nil? routes resources :valuations do resources :comments

ActionController::Live with SSE not working properly

血红的双手。 提交于 2019-12-08 07:33:55
问题 I'm trying to use Live Streaming in Rails 4.0.1 in one project but I see problems... I have this action: 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')

Find a newly created record in a controller test using RSpec 3 and Rails 4

丶灬走出姿态 提交于 2019-12-07 23:55:58
问题 I'm doing a controller spec in Rails 4, and I'm wanting to test the attributes of a record created by a controller action. How do I find the newly created record? For example, what could I do instead of it 'Marks a new user as pending' do post :create, params # I don't want to use the following line user = User.last expect(user).to be_pending end The Rails guides only briefly talks about controller tests, where it mentions testing that Article.count changes by 1, but not how to get a new

How to use Rails Action Controller Nested Params to Permit a Specific Attributes Hash

十年热恋 提交于 2019-12-07 09:03:23
问题 There are a lot of questions about Nested Parameters, but I can't seem to find one that addresses my specific, simple situation. I'm trying to permit a nested hash that is NOT an array. I expected this to work: params.require(:book).permit(:title, :description, style: {:font, :color}) But it resulted in a syntax error. This, however, worked: params.require(:book).permit(:title, :description, style: [:font, :color]) But my issue with this, it it seems to permit style values that are arrays of

How to get ActionController::Live streaming working with Thin?

荒凉一梦 提交于 2019-12-07 03:07:49
问题 Question Can you use thin with ActionController::Live to implement Server Side Events (SSE) and long polling? If so, how? Context Although the title is a repeat of How to get Rails 4 ActionController::Live streaming working with Thin and Ruby 2? And how do Thin and Puma scale with live streaming?, the OP muddied the waters by asking two questions, and this question never got answered. A number of other posts suggest you CAN use thin for Server Side Events (sse) if you start it via exec thin

Getting access to :not_found, :internal_server_error etc. in Rails 3

时光总嘲笑我的痴心妄想 提交于 2019-12-06 11:58:16
问题 It looks like ActionController::StatusCodes has been removed from Rails 3. I used synonyms for HTTP status codes such as 200 => :ok 404 => :not_found 500 => :internal_server_error For more codes, see here: http://apidock.com/rails/ActionController/Base/render#254-List-of-status-codes-and-their-symbols Where can I find these in Rails 3? 回答1: It seems that the error codes reside in action_dispatch/middleware/show_exceptions.rb where the symbols are mapped to actual exceptions: 'ActionController

Find a newly created record in a controller test using RSpec 3 and Rails 4

丶灬走出姿态 提交于 2019-12-06 08:10:22
I'm doing a controller spec in Rails 4, and I'm wanting to test the attributes of a record created by a controller action. How do I find the newly created record? For example, what could I do instead of it 'Marks a new user as pending' do post :create, params # I don't want to use the following line user = User.last expect(user).to be_pending end The Rails guides only briefly talks about controller tests, where it mentions testing that Article.count changes by 1, but not how to get a new ActiveRecord model. The question Find the newest record in Rails 3 is about Rails 3. I'm reluctant to use