Missing template classified/update.erb in view path app/view

Iam trying to build a classified site, I’ve created the code to
add,edit,delete posts. I am facing trouble with the edit part. When I
click the edit link for a post it shows the form with all the
textfields,after entering in all the fields and clicking the save
changes button, Iam getting the error:
“Missing template classified/update.erb in view path app/view”

Update function in the controller looks like:

def update
@classifed = Classified.find(params[:id])
if @classified.update_attributes(params[:classified])
redirect_to :action => ‘show’, :id => @classified
else
render :action => ‘edit’
end
end

show.rhtml looks like

Editing Classified: <%= :title -%>

<% form_for :classified, :url => {:action => 'update'} do |form| %>

Title
<%= form.text_field :title %>

price
<%= form.text_field :price %>

Location
<%= form.text_field :location %>

Description
<%= form.text_area :description %>

Email
<%= form.text_field :email %>

<%= submit_tag “save changes” %>
<% end %>
<%= link_to ‘Back’, {:action => ‘list’} %>

Help will be appreciated. Thanks

Typically your show action does not allow for user input. The edit
action does. In any case, is there a classified/edit.erb and if you are
trying to render it, then it implies that the update failed. Do you know
why?

your show action looks like the edit action should look, and then you
are
rendering edit if something goes wrong , that is not the way

def update
@classifed = Classified.find(params[:id])
if @classified.update_attributes(params[:classified])
redirect_to :action => ‘show’, :id => @classified
else
render :action => ‘edit’ ========> should be render :action=>
“show”
end
end

but you have a mess there , thats the main problem, you are not been
restful

sorry guys,

I made a typo error while posting it here. The show.rhtml file is
actually
named edit.rhtml, I do have another file that is show.rhtml which
renders
the html file. so what I really have is

Update function in the controller looks like:

def update
@classifed = Classified.find(params[:id])
if @classified.update_attributes(params[:classified])
redirect_to :action => ‘show’, :id => @classified
else
render :action => ‘edit’
end
end

edit.rhtml looks like

Editing Classified: <%= :title -%>

<% form_for :classified, :url => {:action => 'update'} do |form| %>

Title
<%= form.text_field :title %>

price
<%= form.text_field :price %>

Location
<%= form.text_field :location %>

Description
<%= form.text_area :description %>

Email
<%= form.text_field :email %>

<%= submit_tag “save changes” %>
<% end %>
<%= link_to ‘Back’, {:action => ‘list’} %>

Well, I’ll try replacing :action => ‘edit’ with :action => ‘show’.
Iam not exactly sure what restful really means. My bad Iam sill a
nOOb. Thanks anyways.

radhames brito wrote:

your show action looks like the edit action should look, and then you
are
rendering edit if something goes wrong , that is not the way

def update
@classifed = Classified.find(params[:id])
if @classified.update_attributes(params[:classified])
redirect_to :action => ‘show’, :id => @classified
else
render :action => ‘edit’ ========> should be render :action=>
“show”
end
end

but you have a mess there , thats the main problem, you are not been
restful

hey guys…long time

I got too busy with my work…my apologies…

I tried the above code I still get errors:

compile error
/Users/alihan/classifieds/app/views/classified/edit.rhtml:5: syntax
error, unexpected ‘>’
/Users/alihan/classifieds/app/views/classified/edit.rhtml:10: syntax
error, unexpected tIDENTIFIER, expecting ‘)’
<%= form.text_field :price ).to_s); @output_buffer.concat “\n”
^
/Users/alihan/classifieds/app/views/classified/edit.rhtml:13: syntax
error, unexpected ‘>’
/Users/alihan/classifieds/app/views/classified/edit.rhtml:18: syntax
error, unexpected tIDENTIFIER, expecting ‘)’
<%= form.text_field :email ).to_s); @output_buffer.concat “\n”
^

Extracted source (around line #5):

2: <% form_for @classified do |form| %>
3: <%=form.error_messages%>
4:


5: <%= form.label :title

6: <%= form.text_field :title %>
7:


8:

Trace of template inclusion: app/views/classified/edit.rhtml

RAILS_ROOT: /Users/alihan/classifieds

thanks…

radhames brito wrote:

what i said was based on the fact that i thought your edit action was
named
show so if it was a typo ignore my comment.

try making this changes and post your routes if it still does not work,
and
what version of rails are you using?

the edit action should be

def edit
@classifed = Classified.find(params[:id])
end

def update
@classifed = Classified.find(params[:id])
if @classified.update_attributes(params[:classified])
flash[:notice] = “updated”
redirect_to @classified
else
render :action => ‘edit’
end
end

Editing Classified: <%= :title -%>

<% form_for @classified do |form| %>
<%=form.error_messages%>

<%=form.label :title%>
<%= form.text_field :title %>

<%=form.label :price%>
<%= form.text_field :price %>

<%=form.label :location%>
<%= form.text_field :location %>

<%=form.label :description%>
<%= form.text_area :description %>

<%=form.label :email%>
<%= form.text_field :email %>

<%= submit_tag “save changes” %>
<% end %>

<%= link_to ‘Back’, {:action => ‘list’} %>

in your routes.rb file it should say

resources classifies, or whatever the plural should be

what i said was based on the fact that i thought your edit action was
named
show so if it was a typo ignore my comment.

try making this changes and post your routes if it still does not work,
and
what version of rails are you using?

the edit action should be

def edit
@classifed = Classified.find(params[:id])
end

def update
@classifed = Classified.find(params[:id])
if @classified.update_attributes(params[:classified])
flash[:notice] = “updated”
redirect_to @classified
else
render :action => ‘edit’
end
end

Editing Classified: <%= :title -%>

<% form_for @classified do |form| %>
<%=form.error_messages%>

<%=form.label :title%>
<%= form.text_field :title %>

<%=form.label :price%>
<%= form.text_field :price %>

<%=form.label :location%>
<%= form.text_field :location %>

<%=form.label :description%>
<%= form.text_area :description %>

<%=form.label :email%>
<%= form.text_field :email %>

<%= submit_tag “save changes” %>
<% end %>

<%= link_to ‘Back’, {:action => ‘list’} %>

in your routes.rb file it should say

resources classifies, or whatever the plural should be

Sorry my bad…please discard the above post, the error was
with the syntax, but now the error I have now is:

Showing app/views/classified/edit.rhtml where line #2 raised:

Called id for nil, which would mistakenly be 4 – if you really wanted
the id of nil, use object_id

1:

Editing Classified: <%= :title -%>


2: <% form_for @classified do |form| %>
3: <%=form.error_messages%>
4:


5: <%= form.label :title%>

radhames brito wrote:

what i said was based on the fact that i thought your edit action was
named
show so if it was a typo ignore my comment.

try making this changes and post your routes if it still does not work,
and
what version of rails are you using?

the edit action should be

def edit
@classifed = Classified.find(params[:id])
end

def update
@classifed = Classified.find(params[:id])
if @classified.update_attributes(params[:classified])
flash[:notice] = “updated”
redirect_to @classified
else
render :action => ‘edit’
end
end

Editing Classified: <%= :title -%>

<% form_for @classified do |form| %>
<%=form.error_messages%>

<%=form.label :title%>
<%= form.text_field :title %>

<%=form.label :price%>
<%= form.text_field :price %>

<%=form.label :location%>
<%= form.text_field :location %>

<%=form.label :description%>
<%= form.text_area :description %>

<%=form.label :email%>
<%= form.text_field :email %>

<%= submit_tag “save changes” %>
<% end %>

<%= link_to ‘Back’, {:action => ‘list’} %>

in your routes.rb file it should say

resources classifies, or whatever the plural should be

k fixed that…
now the error after I hit submit button after editing:

NameError in ClassifiedsController#update

uninitialized constant ClassifiedsController

Help would be appreciated.

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs