ruby - Validation working on edit but template missing error on Create Rails Error -
I am using Rails 4.1.4 and ruby 2.1.2. I am new to Ruby on Rails programming. Validating the form on the I got the missing error in the tape is working for editing the same code but showing this error in creating a new post
Controller:
class post controller & lt; Here's my code for creating / editing posts for a blog. ApplicationController def Indexe @ Post = Post. All FF Show @ Post = Post.Fund (Params [: ID]) F.Def New @ Post = Post.New and Make Diff @Post = Post.New (post_most) @ Post Redirect_to posts_path Save: Notice = & gt; "Your post has been saved" and again a new end-of-the-end def post-param params.require (: post). Parameter (: title, content: edit end DEF @ post = post.find (params [: id]) end def update @ post = Post.find (params [: id]) If @ post.update_attributes (post_params) redirect_to Posts_path ,: notice = & gt; "Post successfully updated" and then "Edit" End End Df Delete @ post = post.find (params [: id]) @ post.destroy redirect_to posts_path, notice = & gt; "Your Post Deleted" End End
Model ::
Class Post
visible files ::
new.html.erb
& lt; H1 & gt; Add new post & lt; / H1> & Lt;% = form_for @ post do | F | | & Gt%; & Lt;% if @search.errors.any? & Gt%; & Lt; H2 & gt; Errors: & lt; / H2 & gt; & Lt; Ul & gt; & Lt;% @ post.errors.full_messages.each do | Message | & Gt%; & Lt; Li & gt; & Lt;% = Message% & gt; & Lt; / Li & gt; & Lt;% end% & gt; & Lt; / Ul & gt; & Lt;% end% & gt; & Lt; P & gt; & Lt;% = f.label: Title% & gt; & Lt; Br / & gt; & Lt;% = f.text_field: Title% & gt; & Lt; Br / & gt; & Lt; / P & gt; & Lt; P & gt; & Lt;% = f.label: Content% & gt; & Lt; Br / & gt; & Lt;% = f.text_area: content% & gt; & Lt; Br / & gt; & Lt; / P & gt; & Lt; P & gt; & Lt;% = f.submit "Add a New Post"% & gt; & Lt; Br / & gt; & Lt; / P & gt; & Lt;% end% & gt;
and edit.html.erb
& lt; H1 & gt; Edit post & lt; / H1> & Lt;% = form_for @ post do | F | | & Gt%; & Lt;% if @search.errors.any? & Gt%; & Lt; H2 & gt; Errors: & lt; / H2 & gt; & Lt; Ul & gt; & Lt;% @ post.errors.full_messages.each do | Message | & Gt%; & Lt; Li & gt; & Lt;% = Message% & gt; & Lt; / Li & gt; & Lt;% end% & gt; & Lt; / Ul & gt; & Lt;% end% & gt; & Lt; P & gt; & Lt;% = f.label: Title% & gt; & Lt; Br / & gt; & Lt;% = f.text_field: Title% & gt; & Lt; Br / & gt; & Lt; / P & gt; & Lt; P & gt; & Lt;% = f.label: Content% & gt; & Lt; Br / & gt; & Lt;% = f.text_area: content% & gt; & Lt; Br / & gt; & Lt; / P & gt; & Lt; P & gt; & Lt;% = f.submit "Update Post"% & gt; & Lt; Br / & gt; & Lt; / P & gt; & Lt;% end% & gt;
Successfully running on verification post. But the problem is that the following error appears in creating a new post:
Template is missing: {= locale = & gt; [: En],: formats = & gt; : Html] ,: variant = & gt; [],: Handlers = & gt; [: ARB ,: Builder ,: raw,: Ruby ,: jbuilder ,: coffee]}.
Your problem is here:
render new < / Code>
This new
method gives a new instance of the post, so it reads as:
render post. New
When a model is found, the effort to present it is partial, so it is looking for a partial view, which is clearly not present. What do you want:
render: new
Comments
Post a Comment