Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Store params in binded page instead of self route handler

  • Loading branch information...
commit e8815e734154d674da4b20af0018052d0a89c906 1 parent 8725a9c
Anton Astashov authored
View
7 app/models/route_handler.rb
@@ -2,8 +2,7 @@ class RouteHandler < ActiveRecord::Base
validates_presence_of :url, :fields, :page_id
- attr_accessor :path_params
- attr_reader :transformed_params
+ cattr_accessor :path_params
belongs_to :page
@@ -23,9 +22,9 @@ def fields
def set_path_params(params)
- self.path_params = {}
+ self.page.route_handler_params ||= {}
fields.each_with_index do |field, index|
- self.path_params[field.to_sym] = params[index]
+ self.page.route_handler_params[field.to_sym] = params[index]
end
end
View
2  route_handler_extension.rb
@@ -14,6 +14,8 @@ class RouteHandlerExtension < Radiant::Extension
def activate
admin.tabs.add "Route Handlers", "/admin/route_handlers", :after => "Layouts"
+ # We will store extracted from path params here
+ Page.class_eval { attr_accessor :route_handler_params }
end
def deactivate
View
1  spec/controllers/route_handler_controller_spec.rb
@@ -24,6 +24,7 @@
response.should be_success
assigns(:route_handler).should == @route_handler
response.body.should include('Hi there!')
+ assigns(:page).route_handler_params.should == { :name => 'dailyoverview', :date => 'today' }
end
it "should show 404 error if there are no matched route handlers" do
View
2  spec/models/route_handler_spec.rb
@@ -29,7 +29,7 @@
handler = RouteHandler.create!(:url => '(\w+)\/(\w+)\/(\w+)', :fields => 'frequency,name,date', :page => @page)
matched_handler = RouteHandler.match('daily/overview/today')
matched_handler.should == handler
- matched_handler.path_params.should == {
+ matched_handler.page.route_handler_params.should == {
:frequency => 'daily',
:name => 'overview',
:date => 'today'
Please sign in to comment.
Something went wrong with that request. Please try again.