c’è ancora molto codice scaffold. comunque il problema di prima l’ho
risolto.
class CustomerController < ApplicationController
def index
list
render :action => ‘list’
end
GETs should be safe (see
URIs, Addressability, and the use of HTTP GET and POST)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }
def list
@customer_pages, @customers = paginate :customers, :per_page => 10,
:order_by => “Surname”
end
def show
@customer = Customer.find(params[:id])
end
def new
@customer = Customer.new
end
def create
@customer = Customer.new(params[:customer])
if @customer.save
flash[:notice] = ‘Customer was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end
def edit
@customer = Customer.find(params[:id])
end
def update
@customer = Customer.find(params[:id])
if @customer.update_attributes(params[:customer])
flash[:notice] = ‘Customer was successfully updated.’
redirect_to :action => ‘show’, :id => @customer
else
render :action => ‘edit’
end
end
def destroy
Customer.find(params[:id]).destroy
redirect_to :action => ‘list’
end
end
class InvoiceController < ApplicationController
def index
list
render :action => ‘list’
end
GETs should be safe (see
URIs, Addressability, and the use of HTTP GET and POST)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }
def list
@invoice_pages, @invoices = paginate :invoices, :per_page => 10
end
def show
@invoice = Invoice.find(params[:id])
end
def new
@invoice = Invoice.new
end
def create
@invoice = Invoice.new(params[:invoice])
if @invoice.save
flash[:notice] = ‘Invoice was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end
def edit
@invoice = Invoice.find(params[:id])
end
def update
@invoice = Invoice.find(params[:id])
if @invoice.update_attributes(params[:invoice])
flash[:notice] = ‘Invoice was successfully updated.’
redirect_to :action => ‘show’, :id => @invoice
else
render :action => ‘edit’
end
end
def destroy
Invoice.find(params[:id]).destroy
redirect_to :action => ‘list’
end
end
questa è la view di customers
Anagrafica Clienti
<%
odd_or_even = 0
for customer in @customers
odd_or_even = 1 - odd_or_even
%>
>
<td width= "60">
<span class ="content h1"><%= (customer.surname) %></span><br />
</td>
<td width= "60">
<span class ="content h1"><%= (customer.name) %></span><br />
</td>
<td class="ListActions">
<%= link_to 'Fattura', :controller => 'invoice', :action =>
‘new’, :customer_id => @custmer %>
<%= link_to ‘Mostra’, :action => ‘show’, :id => customer %>
<%= link_to ‘Modifica’, :action => ‘edit’, :id => customer %>
<%= link_to ‘Cancella’, {:action => ‘destroy’, :id => customer
},
:confirm => “Sei sicuro?” %>
<% end %>
<%= if
@customer_pages.current.previous
link_to(“Pagina prec.”,{ :page =>
@customer_pages.current.previous})
end
%>
<%= if @customer_pages.current.next
link_to("Pagina succ.",{ :page => @customer_pages.current.next})
end
%>
<br />
<%= link_to 'Nuovo cliente', :action => 'new' %>
questa è invece quella di invoice
Elenco fatture
<%
odd_or_even = 0
for invoice in @invoices
odd_or_even = 1 - odd_or_even
%>
>
<td width= "60">
<span class ="content h1"><%= (invoice.invoices_number)
%>
<td width= "60">
<span class ="content h1"><%= (invoice.items) %></span><br />
</td>
<td width= "60">
<span class ="content h1"><%= (invoice.date) %></span><br />
</td>
<td width= "60">
<span class ="content h1"><%= (invoice.customer_id) %></span><br
/>
<td class="ListActions">
<%= link_to 'Mostra', :action => 'show', :id => invoice %>
<%= link_to 'Modifica', :action => 'edit', :id => invoice %>
<%= link_to 'Cancella', {:action => 'destroy', :id => invoice },
:confirm => "Sei sicuro?" %>
</td>
</tr>
<% end %>
</table>
<%= if @invoice_pages.current.previous
link_to("Pagina prec.",{ :page =>
@invoice_pages.current.previous})
end
%>
<%= if @invoice_pages.current.next
link_to("Pagina succ.",{ :page => @invoice_pages.current.next})
end
%>
<br />
<%= link_to 'Nuovo cliente', :action => 'new' %>