I am trying to put render code in my edit.html.erb and create _form.html.erb. I have these code for edit.html.erb
<h1>Main#edit</h1>
<h1>Editing zone</h1>
<%= render partial: "form", locals: {addresses: @addresses} %>
and these code for _form.html.erb
<%= form_for(addresses)do |f| %>
<p>
<b>name</b><br>
<%= f.text_field :address %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
and addresses is a set of address.
and I have this erro: Couldn't find Address with 'id'= Extracted source (around line #21):
def edit
@address = Address.find(params[:id]) this is 21th line
if request.post?
if (@address.update_attributes(address_params))
redirect_to :action=>"index"
would you please help to check anything wrong in my code?
here is the code of my controller:
class MainController < ApplicationController
def index
@addresses = Address.all
end
def new
end
def add
address = Address.new(address_params)
if (address.save)
redirect_to :action=>"index"
else
flash[:notice]="Error saving, try again"
redirect_to :action=>"index"
end
end
def edit
@address = Address.find(params[:id])
if request.post?
if (@address.update_attributes(address_params))
redirect_to :action=>"index"
else
render :action=>"edit"
end
end
end
def delete
address = Address.find(params[:id])
address.destroy
redirect_to :action=>"index"
end
private
def address_params
params.require(:address).permit(:name,:address,:email,:phone)
end
end
here is my model: my data structure