Changeset 216
- Timestamp:
- 04/27/07 13:42:20 (2 years ago)
- Files:
-
- trunk/README (modified) (5 diffs)
- trunk/lib/merb/merb_controller.rb (modified) (1 diff)
- trunk/lib/merb/merb_handler.rb (modified) (1 diff)
- trunk/lib/merb/merb_router.rb (modified) (4 diffs)
- trunk/lib/merb/mixins/controller_mixin.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/README
r209 r216 189 189 *Controllers have powerful before and after filters* 190 190 191 Use the before method in your controllers. before accepts either a symbol 192 or a Proc/lambda object. If you give it a symbol it will call a method with 193 the same name as the symbol. If you give it a proc that takes one argument 194 it will call the proc with the current controller as that argument. You can 195 use :only and :exclude as options to your filters to exclude or include actionsfrom certain filters. :only and :exclude take :symbols or [:sym, :sam] 196 array of symbols. 191 Use the before method in your controllers. before accepts either a symbol, string or a Proc/lambda object. If you give it a symbol it will call a method with the same name as the symbol. If you give it a proc that takes one argument it will call the proc with the current controller as that argument. You can use :only and :exclude as options to your filters to exclude or include actionsfrom certain filters. :only and :exclude take :symbols or [:sym, :sam] array of symbols. 197 192 198 193 class Foo < Merb::Controller … … 232 227 # halts the chain and returns whatever is in the string 233 228 234 throw :halt, "<h1>You don't have permissions IDIOT!</h1>"229 throw :halt, "<h1>You don't have permissions dude!</h1>" 235 230 236 231 or even render templates: … … 247 242 248 243 Helpers: dist/app/helpers/global_helper.rb will be available to all of your views. 249 Helpers named af dter your controller plus _helper.rb will be included in the views244 Helpers named after your controller plus _helper.rb will be included in the views 250 245 for that controller only. 251 246 … … 274 269 This is one of the things that Merb was written for. Rails doesn't allow 275 270 multiple concurrent file uploads at once without blocking an entire rails backend for each file upload. Merb allows multiple file uploads at once. 276 progress bar.When a file is uploaded with Merb, it gets put in a Tempfile. So271 When a file is uploaded with Merb, it gets put in a Tempfile. So 277 272 you just want to copy it to the right place on the filesystem. 278 273 … … 289 284 :filename => File.basename(filename), 290 285 :content_type => content_type, 291 :tempfile => body,286 :tempfile => <Tempfile>, 292 287 :size => File.size(body) 293 288 } trunk/lib/merb/merb_controller.rb
r200 r216 82 82 call_filters(after_filters) 83 83 finalize_session if respond_to?:finalize_session 84 MERB_LOGGER.info("Time spent in #{ action} action: #{Time.now - start} seconds")84 MERB_LOGGER.info("Time spent in #{self.class}##{action} action: #{Time.now - start} seconds") 85 85 end 86 86 trunk/lib/merb/merb_handler.rb
r198 r216 63 63 else 64 64 begin 65 # dLet Merb:Dispatcher find the route and call the filter chain and action65 # Let Merb:Dispatcher find the route and call the filter chain and action 66 66 controller = nil 67 67 controller, action = Merb::Dispatcher.handle(request, response) trunk/lib/merb/merb_router.rb
r207 r216 75 75 # of the route def that start with : and turns them 76 76 # into placeholders for whatever urls match against 77 # the route in question. Special case for the default 78 # /:controller/:action/:id route. 77 # the route in question. 79 78 def self.compile(route) 80 79 raise ArgumentError unless String === route[0] … … 159 158 def self.generate_resources_routes(res,opt) 160 159 with_options :controller => res.to_s, :rest => true do |r| 161 r.add "#{opt[:prefix]}/#{res}/:id[;/] edit", :allowed => {:get => 'edit'}162 r.add "#{opt[:prefix]}/#{res}/new[;/] :action", :allowed => {:get => 'new', :post => 'new', :put => 'new', :delete => 'new'}160 r.add "#{opt[:prefix]}/#{res}/:id[;/]+edit", :allowed => {:get => 'edit'} 161 r.add "#{opt[:prefix]}/#{res}/new[;/]+:action", :allowed => {:get => 'new', :post => 'new', :put => 'new', :delete => 'new'} 163 162 r.add "#{opt[:prefix]}/#{res}/new" , :allowed => {:get => 'new'} 164 163 if mem = opt[:member] 165 164 mem.keys.sort_by{|x| "#{x}"}.each {|action| 166 165 allowed = mem[action].injecting({}) {|h, verb| h[verb] = "#{action}"} 167 r.add "#{opt[:prefix]}/#{res}/:id[;/] #{action}", :allowed => allowed166 r.add "#{opt[:prefix]}/#{res}/:id[;/]+#{action}", :allowed => allowed 168 167 } 169 168 end … … 171 170 coll.keys.sort_by{|x| "#{x}"}.each {|action| 172 171 allowed = coll[action].injecting({}) {|h, verb| h[verb] = "#{action}"} 173 r.add "#{opt[:prefix]}/#{res}[;/] #{action}", :allowed => allowed172 r.add "#{opt[:prefix]}/#{res}[;/]+#{action}", :allowed => allowed 174 173 } 175 174 end … … 183 182 def self.generate_singleton_routes(res,opt) 184 183 with_options :controller => res.to_s, :rest => true do |r| 185 r.add "#{opt[:prefix]}/#{res}[;/] edit", :allowed => {:get => 'edit'}184 r.add "#{opt[:prefix]}/#{res}[;/]+edit", :allowed => {:get => 'edit'} 186 185 r.add "#{opt[:prefix]}/#{res}\\.:format", :allowed => {:get => 'show'} 187 186 r.add "#{opt[:prefix]}/#{res}/new" , :allowed => {:get => 'new'} trunk/lib/merb/mixins/controller_mixin.rb
r209 r216 168 168 end 169 169 170 # stream_file( { :filename => file_name, 171 # :type => content_type, 172 # :content_length => content_length }) do 173 # @response.send_status(opts[:content_length]) 174 # @response.send_header 175 # AWS::S3::S3Object.stream(user.folder_name + "-" + user_file.unique_id, bucket_name) do |chunk| 176 # @response.write chunk 177 # end 178 # end 179 def stream_file(opts={}, &stream) 180 opts.update(Merb::Const::DEFAULT_SEND_FILE_OPTIONS.merge(opts)) 181 disposition = opts[:disposition].dup || 'attachment' 182 disposition << %(; filename="#{opts[:filename]}") 183 @response.headers.update( 184 'Content-Type' => opts[:type].strip, # fixes a problem with extra '\r' with some browsers 185 'Content-Disposition' => disposition, 186 'Content-Transfer-Encoding' => 'binary', 187 'CONTENT-LENGTH' => opts[:content_length] 188 ) 189 stream 190 end 191 192 170 193 # This uses nginx X-Accel-Redirect header to send 171 194 # a file directly from nginx. See the nginx wiki:
