K.M.
2011-Sep-28 11:00 UTC
filters defined in :before_filter does not seem to get fired when ajax requests are made to the methods in the :before_filter
hi, guys
My rails 3 app is working fine except for resource deletion which uses
ajax.
The resource is "part".
When the user clicks on the "delete part" link, a confirmation pop up
box will appear.
Upon clicked on "ok", an ajax request is fired to the
''delete'' method
in my controller.
In the "parts" controller, I have a before_filter which points to a
method
which checks if the current user has authorisation to delete the given
part entry.
This method works fine for my other methods specified in the
before_filter but doesn''t for the deletion method.
------------------ extract from: app/view/parts/index.html.erb (start)
---------------------------
<% link_to ''Delete'',
part_path(part.id),
#''data-method'' =>
''delete'',
:method => :delete,
''data-confirm'' => ''Are you
sure?'',
''data-remote'' =>
''true'',
''class'' =>
''delete_part''
%>
------------------ extract from: app/view/parts/index.html.erb (end)
---------------------------
Javascript framework: Jquery
Rails version 3.0.9
Javascript/rails gem: ''jquery-rails'' version 1.0.14
I noticed that the ajax call somehow bypasses the before filter.
Why is this so and is there any way to fix this?
Thank you
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
K.M.
2011-Sep-28 11:16 UTC
Re: filters defined in :before_filter does not seem to get fired when ajax requests are made to the methods in the :before_filter
I''ve done some extra checks and observed that with Javascript turned
off on my web browsers (chrome and firefox),
the destroy method does not get called when I click on it.
in app/views/parts/index.html.erb, i observed that I was using
":method => delete"
to generate the deletion link.
I have changed it to use ''data-method''=> :delete but it
still does not
work :(
link_to ''Delete'',
part_path(part.id),
:method => :delete,
''data-confirm'' =>
''Are you
sure?'',
''data-remote'' =>
''true'',
''class'' =>
''delete_part''
to
link_to ''Delete'',
part_path(part.id),
''data-method'' =>
:delete,
''data-confirm'' =>
''Are you
sure?'',
''data-remote'' =>
''true'',
''class'' =>
''delete_part''
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
K.M.
2011-Sep-28 11:17 UTC
Re: filters defined in :before_filter does not seem to get fired when ajax requests are made to the methods in the :before_filter
On Sep 28, 9:00 pm, "K.M." <anexi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, guys > > My rails 3 app is working fine except for resource deletion which uses > ajax. > The resource is "part". > > When the user clicks on the "delete part" link, a confirmation pop up > box will appear.I''ve done some extra checks and observed that with Javascript turned off on my web browsers (chrome and firefox),the destroy method does not get called when I click on it. in app/views/parts/index.html.erb, i observed that I was using ":method => delete" to generate the deletion link. I have changed it to use ''data-method''=> :delete but it still does not work :( link_to ''Delete'', part_path(part.id), :method => :delete, ''data-confirm'' => ''Are you sure?'', ''data-remote'' => ''true'', ''class'' => ''delete_part'' to link_to ''Delete'', part_path(part.id), ''data-method'' => :delete, ''data-confirm'' => ''Are you sure?'', ''data-remote'' => ''true'', ''class'' => ''delete_part''> Upon clicked on "ok", an ajax request is fired to the ''delete'' method > in my controller. > > In the "parts" controller, I have a before_filter which points to a > method > which checks if the current user has authorisation to delete the given > part entry. > > This method works fine for my other methods specified in the > before_filter but doesn''t for the deletion method. > > ------------------ extract from: app/view/parts/index.html.erb (start) > --------------------------- > > <%> link_to ''Delete'', > part_path(part.id), > #''data-method'' => ''delete'', > :method => :delete, > ''data-confirm'' => ''Are you sure?'', > ''data-remote'' => ''true'', > ''class'' => ''delete_part'' > %> > > ------------------ extract from: app/view/parts/index.html.erb (end) > --------------------------- > > Javascript framework: Jquery > Rails version 3.0.9 > Javascript/rails gem: ''jquery-rails'' version 1.0.14 > > I noticed that the ajax call somehow bypasses the before filter. > Why is this so and is there any way to fix this? > > Thank you-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
K.M.
2011-Sep-28 11:43 UTC
Re: filters defined in :before_filter does not seem to get fired when ajax requests are made to the methods in the :before_filter
My bad... I put "delete" in the :before_filter''s list of methods when the method name is "destroy". Silly gotcha. Sorry gents. Hope someone facing roughly the same issue would benefit from this little lesson I learnt. Cheers :) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.