I have a model called sample. To simplify, "sample" will have a "name", "price" and "approved" fields.
I want to have a page that will list all samples that have "approved = 'false'". In this page I want to be able to edit the sample fields, check the approved checkbox when done, and then press the form button to approve all the selected sample fields.
I watched railscast #198 but it has a previous page that I want to avoid... He has a webpage listing all samples, and then check the ones he wants to edit and then he finally has access to the "edit individual" page. I want to skip this page and go directly to the approve page.
On my sample controller I've got:
def edit_individual
@samplestoapprove = Sample.where(:approve => 'false')
end
On my routes.rb I have:
resources :samples, :collection => { :edit_individual => :post, :update_individual => :put }
If we ignore for now the "update_individual" code on the controller,I then created a view inside samples, just to check if I could list the unapproved samples. I called it "edit_individual.html.erb"
<% title "Edit Samples" %>
<%= form_tag update_individual_samples_path :method => :put do %>
<%= for sample in @samplestoapprove %>
<%= fields_for "samplestoapprove[]", sample do |f| %>
<h2><%= f sample.id %></h2>
<%= end %>
<%= end %>
<p><%= submit_tag "Approve" %></p>
<%= end %>
I then tried to access "localhost:3000/samples/edit_individual" but I get an error "Couldn't find Sample with id=edit_individual"
Can anyone help me? I want to have an option on the menu called "Approve" with a link to this "edit_individual" that when I click it, it shows me all samples to be approved with the form mentioned before... Is this easy to achieve? I'm a going on the right path?
Or should I go for something like a datagrid? Like for example http://www.tutorialized.com/tutorial/Editable-Datagrid-for-Ruby-on-Rails-Built-with-dhtmlxGrid/60309
Here's the code on my routes.rb related to this issue:
resources :samples, :collection => { :get => :edit_individual,
:update_individual => :put}