Skip to content

FIXED Rails 4.0.0.beta1 undefined method `header' for #<ActionDispatch::Journey::Routes:0x9adc8a8> #9815

Closed
ozpos opened this Issue Mar 19, 2013 · 5 comments

2 participants

@ozpos
ozpos commented Mar 19, 2013

This is now done a different way:-

# Define all resources
Rails.application.reload_routes!
all_routes = Rails.application.routes.routes

# Populate a table of controller and action names and controller_actions.
# Create Webmaster default role for each secure_resource.
all_routes.routes.each do |route|
  w = ActionDispatch::Routing::RouteWrapper.new(route)
  if w.endpoint == w.controller + "#" + w.action and !w.internal?
    c = ControllerName.find_or_create_by_name(w.controller)
    a = ActionName.find_or_create_by_name(w.action)
    res = ControllerAction.find_or_create_by_name(w.endpoint, :controller_name_id => c.id, :action_name_id => a.id)
    if !res.roles.include? 'Webmaster'
      role = Role.find_by_name('Webmaster')
      Interaction.create!([{:role_id => role.id, :controller_action_id => res.id}])
    end
  end
end

In my seeds.rb file:-

Rails.application.reload_routes!
all_routes = Rails.application.routes.routes

require 'action_dispatch/routing/inspector'
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)

r =[]
for routeRule in inspector.format(all_routes, ENV['CONTROLLER'])
  # Parse routeRule to get your values
  routeRule.split(' ').each do |s|
    r << s if s.include?('#')
  end
end

The call inspector.format(all_routes, ENV['CONTROLLER']) generates the above error.

@senny
Ruby on Rails member
senny commented Mar 22, 2013

This PR #8658 changed the API of the inspector. It's now using a formatter to display the routes in various formats: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/inspector.rb#L90-L109

As you are passing all_routes as a formater, it does not work. I don't think this is a bug as you are not using the API as intended. Can you confirm so that we can close this ticket?

Also: please use ``` to format the code in your tickets. Otherwise it is extremely hard to read (I edited your message).

@ozpos
ozpos commented Mar 22, 2013

Hi, Thank you for the response. My mistake I was porting working code from 3.2.

I eventually realised the errors of my ways and amended the subject with FIXED because I did not know the right way to retract. Also I thought it might be useful to others to see the right way of obtaining all the routers endpoint info.

Sorry about the code format, again I did not know. Thank you again.

@ozpos ozpos closed this Mar 22, 2013
@senny
Ruby on Rails member
senny commented Mar 22, 2013
@ozpos
ozpos commented Mar 22, 2013
@senny
Ruby on Rails member
senny commented Mar 22, 2013

@ozpos this ticket is not the right place for this discussion. Please post on the rails core mailing list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.