jonleighton / focused_controller

MIT License
468 stars 27 forks source link

Controller params not fill #14

Closed shingara closed 12 years ago

shingara commented 12 years ago

If I check the params fill in my controller. the controller is not fill like do in Rails way. If I do a params[:controller] on my controller, it's return nil.

I think it's better to return the controller name.

kristianmandrup commented 12 years ago

Yeah, it doesn't really "fit" the Rails convention, but then again, how could it, when it is designed not to follow the Rails convention? For the same reason, I don't see how the url_for(options) can work? I think Rails (4.0) needs to be updated to be more flexible with regards to path generation. Perhaps it should be possible to register a Route Mapper that can map any sort of hash (or whatever routing object)?

kristianmandrup commented 12 years ago

Hmm, maybe you are right? Every Action is a kind of Controller. So the #run method should set:

params[:controller] = self.class.name and `params[:action] = 'run'``

One hacky way to achieve this (see my fork):

      def run &block
        define_method :run do
           params[:controller] = self.class.name
           params[:action] = 'run'
           instance_eval &block
      end

module PostController class Show < Action run do

run code here!

end

end end


Not sure however, if this would disrupt the use of the `:to` parameter?
jonleighton commented 12 years ago

I think you shouldn't use params for this. Use the controller_name and action_name methods instead. I've made controller_name work in fb86396b7f833101a25cc87e044ce8b11a565664.