Missing Template Error

21 views
Skip to first unread message

Aditya Tyagi

unread,
May 25, 2016, 7:41:36 AM5/25/16
to rubyonra...@googlegroups.com
i am getting the missing template error when i try to update my post.

Missing template posts/update, application/update with {:locale=>[:en],
:formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw,
:ruby, :coffee, :jbuilder]}. Searched in: *
"c:/Sites/myrubyblog/app/views"

EDIT.HTML.ERB

<h1>Edit Post</h1>


<%= form_for @post do |f| %>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %><br />
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %><br />
</p>
<p>
<%= f.select :category_id, Category.all.collect {|x| [x.name,
x.id]}, {:include_blank => "Select One"} %><br />
</p>
<p>
<%= f.submit "Update Post" %><br />
</p>

<% end %>
<% link_to "Go Back",post_path %>
--------------------------------------------------------------

POST_CONTROLLER.RB

class PostsController < ApplicationController
def index
@posts = Post.all
end

def show
@post = Post.find(params[:id])
end

def new
@post = Post.new
@category = Category.all
end

def create
@post = Post.new(post_params)
if @post.save
redirect_to posts_path, :notice => "Your post has been saved"
else
render "new"
end
end

def post_params

params.require(:post).permit(:category_id, :title, :body)

end

def edit
@post = Post.find(params[:id])
end

def update

end

def destroy

end

end

--
Posted via http://www.ruby-forum.com/.

Dave Aronson

unread,
May 25, 2016, 7:51:59 AM5/25/16
to rubyonrails-talk
On Wed, May 25, 2016 at 7:40 AM, Aditya Tyagi wrote:

> i am getting the missing template error when i try to update my post.
>
> Missing template posts/update, application/update
...
> POST_CONTROLLER.RB
>
> class PostsController < ApplicationController
...
> def update
>
> end

Once you have typical code in the controller to handle updates, you'll
no longer have this problem. A typical update action redirects to
show on success, and renders the edit template on failure. Either
one, though, is *explicit*. As several posters here regularly say, I
recommend you work your way straight through a good tutorial, such as
https://www.railstutorial.org/.

-Dave

--
Dave Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.

Praveen Kumar

unread,
May 25, 2016, 7:55:13 AM5/25/16
to rubyonra...@googlegroups.com
your update action is blank. You have to render something or redirect to some other page. I mean it has to have some response.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHxKQijR24VzWNo_A%2BD37mjhbfLnSAQLA3zKP0U1wTXnQwcN2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Aditya Tyagi

unread,
May 25, 2016, 8:00:14 AM5/25/16
to rubyonra...@googlegroups.com
@praveen_k95

thank you for replying.
i know, the update action is blank. but i am trying to edit this post
already made. therefore i am working through edit only.
actually i am trying to follow this tutorial and he is using 1.9.3
version of ROR, and i am working on 4, and thats creating alot of
issues.

Walter Lee Davis

unread,
May 27, 2016, 8:13:06 AM5/27/16
to rubyonra...@googlegroups.com

> On May 25, 2016, at 7:59 AM, Aditya Tyagi <li...@ruby-forum.com> wrote:
>
> @praveen_k95
>
> thank you for replying.
> i know, the update action is blank. but i am trying to edit this post
> already made. therefore i am working through edit only.
> actually i am trying to follow this tutorial and he is using 1.9.3
> version of ROR, and i am working on 4, and thats creating alot of
> issues.


Wow. Really find a newer tutorial. You are going to have such a translation problem between then and now that you are only going to hurt yourself. The only reason to mess with that version of Rails is if someone dumps a lot of money on you to upgrade it (rewrite it, at that distance) to current. The http://railstutorial.org is free to use on line and one of the best-written tutorials on any subject I have ever seen. It covers Rails 4.2, which is the current (soon to be less so with 5 coming out). I can't find a reference to Rails 1.9.3 (maybe you mean Ruby?), but if that's really the version, that's from 2007 or so. A lot has changed.

Walter

>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5140ad78f34c8cc1deef00c0cb65bd0d%40ruby-forum.com.
Reply all
Reply to author
Forward
0 new messages