Ruby on Rails - redirect_to -
i'm having trouble understanding redirect_to statement. have model "book" (with boolean attribute "read")and controller "books". created second controller "admins" having methods: index , change. index view renders list off books link change method:
<% @books.each |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 change method changes "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 redirect me show action using :id parameter...(perhaps because change_url /admins/change?id=3) want directed index view "/admins"
is there way? seems rails tries redirect view action if there id parameter
thanks alot
ps: routes.rb contains resources:admins , resources:books
if want clear explanation of redirect_to ... checkout
Comments
Post a Comment