Monday 15 April 2013

json - How to add another method in rails controller -


I'm having trouble adding a new method to the controller, here are the details:

matches_controller.rb

  DIF index @ matches = match. All rambler render: @mats and df current @ matches = match.fund_b_sql ("select * fade" Test start: rmat: @matches end   

routes.rb

  resources: matches, default: {format :: Json}, except: Edit, Edit: Current End and   

current .json.rabl

  Archive @ Match Features: ID: Live   

Rake Routes Match current_matches get / match / current (. Format) matches # current {: format = & gt;: json} match GIT / Mets (.: Format) match # index {: format = & gt; Json} POST / matches (. {Format = & gt;: json} new_match GET /matches/new(.:format) #new {: format = & gt ;: json} match GIT / Mets /: id (.: Fo rmat) match #shows {: format = & gt ;: json} PUT /matches/:id(.:format) match # update {: format = & gt ;: json} DELETE /matches/:id(.:format ) Delete matches #: {= format = & gt ;: json}

Error in log

  name error (undefined local variable or method `flash '# and lieutenant; For Match Controller: 0x0000000d7b2368>): Block in app / controller / application_controller.rb: 6: in & lt; Class: ApplicationController & gt;   

application.rb

  Class ApplicationController & lt; ActionController :: API ActionController :: MimeResponds includes CanCan :: ControllerAdditions rescue_from CanCan :: AccessDenied do | Exceptions | Flash [: Error] = Exception. Message Exceptions Message redirect_to root_url end DEF log_exception (exception) logger. Terror (Exception Message) Logger. Terror (Exceptions Backtrace.join ("\ n") End End   

I have done this in another application before, I do not know why this is not working.

You can also close Flash directly to rescue_from Can not access the blocked block. However, if you pass the symbol of the exception handler method, then you can reach Flash . For example:

  class ApplicationController & lt; ActionController :: API rescue_from CanCan :: AccessDenied, with: with> & gt; : Access_denied Private def access_denied (exception) Flash [: Error] = Exception. Redirect Message Root_Arnal End End   

For more information, see the section on rescue_from .

No comments:

Post a Comment