Rails 3: I have a view books/:id/show.html.erb - in the view, I have a form with a select tag to pick a template, that on dropdown should submit the form which rerenders the page based on the selection:
<%= form_tag book_path(@book) do %> <%= select_tag “template”, options_for_select([[“Template1”,“template1”], [“Template2”, “template2”]]), :value => (@template || ‘template1’), :onchange => ‘this.form.submit();’ %> <%end%>
In my controller, I have
@template = params[:template] || ‘post’
In my routes, I have
resources :books, :only => [:show]
and rake routes indeed shows
book GET /books/:id(.:format) {:controller=>“books”, :action=>“show”}
When I first navigate to this view, it all works fine and the view renders as expected. If I select a different template from the dropdown, I get the error:
No route matches ‘books/1’
The funny thing is that the current page is exactly that route.
If I refresh the page, it renders with the default template (and not the selected one).
Any help?
Thanks
Anand