Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Blank Edit form with MYSQL Database


  • Please log in to reply
4 replies to this topic

#1 k3v1np

k3v1np

    Passenger

  • Members
  • 3 posts

Posted 26 May 2014 - 04:47 PM

I'm a ROR newbie and just going through a Youtube tutorial on ROR and MYSQL and have run into a snag that I think maybe due to the fact that I'm using a newer version of rails than what the tutorial is.  When I create an edit form it displays no fields on the webpage just the title of the page. Adding a new record works fine.  This is the tutorial 

I have included the code that I think is important.  I hope that this is not just a type-o.  It shouldn't be because I went through the tutorial from scratch twice and ended up with the same results when I got to the "Edit" a record part.  

 

index.html.rb

<h1>Our Blog</h1>

<% @posts.each do |post|%>
	<h2><%= link_to post.title, post %></h2>
	<p><%= post.content %></p>
	<p><%= link_to "Edit", edit_post_path(post) %></p>
	<hr />
<% end %>

<p><%= link_to "Add a New Post", new_post_path %></p>

edit.html.erb

<h1>Edit Post</h1>

<% form_for @post do |f| %>
	<p>
		<%= f.label :title %><br />
		<%= f.text_field :title %>
	</p>
	<p>
		<%= f.label :content %><br />
		<%= f.text_area :content %>
	</p>
	<p>
		<%= f.submit "Update Post" %>
	</p>
<% end %>

posts_controller.rb

class PostsController < ApplicationController
	def index
		@posts = Post.all
	end
	
	def show
		@post = Post.find(params[:id])
	end
	
	def new
		@post = Post.new
	end
	
	def create
	@post = Post.new(post_params)
		
		if @post.save
			redirect_to posts_path, :notice => "The new post was saved"
		else
			render "new"
		end
	end
	
	def edit
		@post = Post.find(params[:id])
	end
	
	def update
		
	end
	
	def destroy
		
	end
end

private

def post_params
	params.require(:post).permit(:title,:content)
end 


#2 palytoxin

palytoxin

    Passenger

  • Members
  • 9 posts

Posted 27 May 2014 - 05:12 AM

let me see your html file in web browser.

 

what's that there in the body tag?



#3 k3v1np

k3v1np

    Passenger

  • Members
  • 3 posts

Posted 27 May 2014 - 06:29 AM

<!DOCTYPE html>
<html>
<head>
  <title>Blog</title>
  <link data-turbolinks-track="true" href="/assets/posts.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
  <script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/posts.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/application.js?body=1"></script>
  <meta content="authenticity_token" name="csrf-param" />
<meta content="+kILh0p+iEi/ZK9HCPuoC4DHEBVq7ropuL4hUQGCTlE=" name="csrf-token" />
</head>
<body>


<h1>Edit Post</h1>



</body>
</html>



#4 k3v1np

k3v1np

    Passenger

  • Members
  • 3 posts

Posted 28 May 2014 - 12:46 AM   Best Answer

SOB!!! it was a type-o in edit.html.erb, should have been

 

<%= form_for @post do |f| %>

 

and not 

 

<% form_for @post do |f| %>



#5 palytoxin

palytoxin

    Passenger

  • Members
  • 9 posts

Posted 28 May 2014 - 01:03 AM

oh, yes

Edited by palytoxin, 28 May 2014 - 01:12 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users