Permalink
Browse files

In some situations like in ruby 1.9.2 .methods returns symbols rather…

… than strings. Also fixes a case where the refinery setting id was being passed as an actual id and not the name that we were expecting.
  • Loading branch information...
1 parent 995feba commit 26e2d2b0735c506e4ed442b66f55f7d66a0e450b @parndt parndt committed Aug 31, 2010
View
19 app/controllers/admin/inquiry_settings_controller.rb
@@ -1,9 +1,12 @@
class Admin::InquirySettingsController < Admin::BaseController
- crudify :refinery_setting, :title_attribute => "name", :order => 'name ASC', :redirect_to_url => "admin_inquiries_url"
+ crudify :refinery_setting,
+ :title_attribute => "name",
+ :order => 'name ASC',
+ :redirect_to_url => "admin_inquiries_url"
before_filter :redirect_back_to_inquiries?, :only => [:index]
- before_filter :set_url_override?, :only => [:edit]
+ before_filter :set_url_override?, :only => [:edit, :update]
after_filter :save_subject_for_confirmation?, :only => [:create, :update]
around_filter :rewrite_flash?, :only => [:create, :update]
@@ -23,12 +26,20 @@ def redirect_back_to_inquiries?
end
def set_url_override?
- @url_override = admin_inquiry_setting_url(@refinery_setting.name.to_sym, :dialog => from_dialog?)
+ @url_override = admin_inquiry_setting_url(@refinery_setting, :dialog => from_dialog?)
end
def find_refinery_setting
+ # ensure that we're dealing with the name of the setting, not the id.
+ begin
+ if params[:id].to_i.to_s == params[:id]
+ params[:id] = RefinerySetting.find(params[:id]).name.to_s
+ end
+ rescue
+ end
+
# prime the setting first, if it's valid.
- if InquirySetting.methods.include?(params[:id].to_s.gsub('inquiry_', ''))
+ if InquirySetting.methods.map(&:to_sym).include?(params[:id].to_s.gsub('inquiry_', '').to_sym)
InquirySetting.send(params[:id].to_s.gsub('inquiry_', '').to_sym)
end
@refinery_setting = RefinerySetting.find_by_name(params[:id])
View
9 app/models/inquiry_setting.rb
@@ -7,19 +7,22 @@ def self.confirmation_body
end
def self.confirmation_subject
- RefinerySetting.find_or_set(:inquiry_confirmation_subject, "Thank you for your inquiry")
+ RefinerySetting.find_or_set(:inquiry_confirmation_subject,
+ "Thank you for your inquiry")
end
def self.confirmation_subject=(value)
RefinerySetting[:inquiry_confirmation_subject] = value
end
def self.notification_recipients
- RefinerySetting.find_or_set(:inquiry_notification_recipients, (Role[:refinery].users.first.email if defined?(Role)))
+ RefinerySetting.find_or_set(:inquiry_notification_recipients,
+ (defined?(Role) ? Role[:refinery].users.first.email : '' rescue ''))
end
def self.notification_subject
- RefinerySetting.find_or_set(:inquiry_notification_subject, "New inquiry from your website")
+ RefinerySetting.find_or_set(:inquiry_notification_subject,
+ "New inquiry from your website")
end
end
View
2 refinerycms-inquiries.gemspec
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'refinerycms-inquiries'
- s.version = '0.9.8.2'
+ s.version = '0.9.8.3'
s.summary = 'Inquiry handling functionality for the Refinery CMS project.'
s.required_ruby_version = '>= 1.8.7'
s.description = "Inquiry handling functionality extracted from Refinery CMS to allow you to have a contact form and manage inquiries in the Refinery backend."

0 comments on commit 26e2d2b

Please sign in to comment.