I am trying to get my submit button for to be on a different page but I get this error. I have the following in my show.html.erb,
<%= render 'form' %>
<button type="button" class="btn btn-primary"><%= f.submit %></button>
This is in my _form.html.erb page,
<% form_for @post do |f| %>
</div>
<p>
<%= f.label :body %><br>
<%= f.text_area :body %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
This is in my posts_controller.rb,
class PostsController < ApplicationController
def index
@posts = Post.all.order("created_at DESC")
end
def welcome
@user = User.find(session[:user_id])
@post = Post.find(params[:id])
@posts = Post.order("created_at desc").limit(4).offset(1)
@signed_in_user = session[:user_id]
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
@post.user_id = @signed_in_user
if @post.save
redirect_to dashboard_path
else
render 'new'
end
end
def show
@user = User.find(session[:user_id])
@post = Post.find(params[:id])
@posts = Post.order("created_at desc").limit(4).offset(1)
@signed_in_user = session[:user_id]
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update(params[:post].permit(:body))
redirect_to @post
else
render 'edit'
end
end
def destroy
@post = Post.find(params[:id])
@post.user_id = @signed_in_user
@post.destroy
redirect_to posts_path
end
private
def post_params
params.require(:post).permit(:body)
end
end
I have even tried rendering partials thinking that maybe it could help, I have tried several things overall but can't seem to figure this out. I am sure its very simple and I am missing it but if you know how to fix it then post your answer and thank you in advance! I can also add any other code you may need to see that can help this process!
Aucun commentaire:
Enregistrer un commentaire