daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest May 25th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Application < Merb::Controller
  2.   extend Merb::ResourceController::Mixin::ClassMethods
  3. end
  4.  
  5. class Articles < Application
  6.  
  7.   controlling :articles
  8.  
  9.   # this defines (among others) the following method:
  10.  
  11.   # this DOESN'T WORK because the parameter name is expected to be article here!
  12.   def create(attributes)
  13.     member = new_member(attributes)
  14.     if member.save
  15.       options = flash_supported ? { :message => successful_create_messages } : {}
  16.       redirect resource(member), options
  17.     else
  18.       message.merge!(failed_create_messages) if flash_supported?
  19.       render :new
  20.     end
  21.   end
  22.  
  23.   # this WORKS (parameter name hash key inferred using common conventions):
  24.   def create
  25.     member = new_member(params[self.class.name.singular.snake_case.to_sym])
  26.     if member.save
  27.       options = flash_supported ? { :message => successful_create_messages } : {}
  28.       redirect resource(member), options
  29.     else
  30.       message.merge!(failed_create_messages) if flash_supported?
  31.       render :new
  32.     end
  33.   end
  34. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top