actioncontroller

How to allow Binary File download using GRAPE API

那年仲夏 提交于 2019-12-03 09:48:08
问题 I want to allow downloading a binary file (.p12 file) using ruby's Grape API. This is what I am trying. get '/download_file' do pkcs12 = generate_pkcsfile content_type('application/octet-stream') body(pkcs12.der) end The equivalent code using ActionController is begin pkcs12 = generate_pkcsfile send_data(pkcs12.der, :filename => 'filename.p12') end The problem is the file downloaded using the API seems to be a text file with a '\ufffd' prefix embedded for every character, whereas the file

Does Rails come with a “not authorized” exception?

孤街醉人 提交于 2019-12-03 01:07:41
I am writing an application that uses plain old Ruby objects (POROs) to abstract authorization logic out of controllers. Currently, I have a custom exception class called NotAuthorized that I rescue_from at the controller level, but I was curious to know: Does Rails 4 already come with an exception to indicate that an action was not authorized? Am I reinventing the wheel by implementing this exception? Clarification : The raise AuthorizationException is not happening anywhere inside of a controller, it is happening inside of a completely decoupled PORO outside of the controller. The object has

How to allow Binary File download using GRAPE API

∥☆過路亽.° 提交于 2019-12-03 00:14:16
I want to allow downloading a binary file (.p12 file) using ruby's Grape API. This is what I am trying. get '/download_file' do pkcs12 = generate_pkcsfile content_type('application/octet-stream') body(pkcs12.der) end The equivalent code using ActionController is begin pkcs12 = generate_pkcsfile send_data(pkcs12.der, :filename => 'filename.p12') end The problem is the file downloaded using the API seems to be a text file with a '\ufffd' prefix embedded for every character, whereas the file downloaded using the browser seems to be binary file. How do I use the GRAPE API framework to allow

How to do “actionSheet showFromRect” in iOS 8?

旧巷老猫 提交于 2019-12-01 07:39:29
In iOS 7, I show actionSheet by "showFromRect": [actionSheet showFromRect:rect inView:view animated:YES]; But in iOS 8, this doesn't work. They they replace the implementation and suggest us using UIAlertController. Then how do I show this actionSheet like a popover? Using UIAlertController you can access the popoverPresentationController property to set the sourceView (aka inView) and sourceRect (aka fromRect). This gives the same appearance as the previous showFromRect:inView: UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle

How to do “actionSheet showFromRect” in iOS 8?

时光怂恿深爱的人放手 提交于 2019-12-01 05:12:26
问题 In iOS 7, I show actionSheet by "showFromRect": [actionSheet showFromRect:rect inView:view animated:YES]; But in iOS 8, this doesn't work. They they replace the implementation and suggest us using UIAlertController. Then how do I show this actionSheet like a popover? 回答1: Using UIAlertController you can access the popoverPresentationController property to set the sourceView (aka inView) and sourceRect (aka fromRect). This gives the same appearance as the previous showFromRect:inView:

How do I configure the hostname for Rails ActionMailer?

拟墨画扇 提交于 2019-11-30 04:46:03
I'm working on a fairly traditional forgot password email - I want to email the user a password change token embedded in a link that they can click on in order to change their password. I'm emailing via the traditional ActionMailer. If I use a normal link_to tag <%= link_to "click here", :controller => foo, :action => 'bar', :token => token %> I get a relative link - rather useless from an email. If I add in :only_path => false , then it errors saying I need to set default_url_options[:host] . The ActionController docs imply that you do that by overriding the #default_url_options methods in

How to set config.action_controller.default_url_options = {:host = '#''} on per environment basis

心不动则不痛 提交于 2019-11-28 17:09:44
Right now I'm using this which works for the development host, but I have to manually change the {:host => ""} code when I move to production. post.rb def share_all url = Rails.application.routes.url_helpers.post_url(self, :host => 'localhost:3000') if user.authentications.where(:provider => 'twitter').any? user.twitter_share(url) end end I'd like to use this and then define the default_url_options per environment: post.rb def share_all url = Rails.application.routes.url_helpers.post_url(self) if user.authentications.where(:provider => 'twitter').any? user.twitter_share(url) end end I've tried

How to set config.action_controller.default_url_options = {:host = '#''} on per environment basis

让人想犯罪 __ 提交于 2019-11-27 20:03:25
问题 Right now I'm using this which works for the development host, but I have to manually change the {:host => ""} code when I move to production. post.rb def share_all url = Rails.application.routes.url_helpers.post_url(self, :host => 'localhost:3000') if user.authentications.where(:provider => 'twitter').any? user.twitter_share(url) end end I'd like to use this and then define the default_url_options per environment: post.rb def share_all url = Rails.application.routes.url_helpers.post_url(self

default_url_options and rails 3

时间秒杀一切 提交于 2019-11-27 01:28:28
As ActionController::Base#default_url_options is deprecated, I wonder how to set default url options in rails3. The default url options are not static but dependent of the current request. http://apidock.com/rails/ActionController/Base/default_url_options Thanks, Corin To set url options for current request use something like this in your controller: class ApplicationController < ActionController::Base def url_options { :profile => current_profile }.merge(super) end end Now, :profile => current_profile will be automerge to path/url parameters. Example routing: scope ":profile" do resources