I'm having some trouble understanding the redirect_to statement. I have a model "Book" (with an boolean attribute "read")and a controller "books". Now I created a second controller "Admins" having to methods: index and change. The index view just renders a list off all Books with a link to the change method:
<% @Books.each do |d| %>
<%= d.title %><br>
<% if d.read==true %>
<%= link_to "mark unread", change_path(:id=>d.id)%>
<% else %>
<%= link_to "mark read", change_path(:id=>d.id)%>
<%end %>
Now the change method just changes the "read" attribute:
@book=Book.find(params[:id])
if @book.read==true
@book.update_attributes(:read => false)
else
@book.update_attributes(:read => true)
end
redirect_to action: "index"
The Problem is: rails tries to redirect me to the show action using the :id as a parameter...(perhaps because the change_url is /admins/change?id=3) But I just want to be directed back to the index view "/admins"
is there a way? it seems like rails always tries to redirect to the view action if there is an id as a parameter
Thanks alot
PS: the routes.rb contains resources:admins and resources:books
rails tries to redirect me to the show action using the :id as a parameter? Do you get any error? If yes, please share the server log generated for the same. - Kirti Thorat