Ask A Question

Notifications

You’re not receiving notifications from this thread.

No action "edit" in forum_posts_controller

Erick Sitter asked in General

Forum_Posts Controller

class ForumThreads::ForumPostsController < ApplicationController
before_action :authenticate_user!
before_action :set_forum_thread
def create
@forum_post = @forum_thread.forum_posts.new forum_post_params
@forum_post.user = current_user

if @forum_post.save
  redirect_to forum_thread_path(@forum_thread, anchor: "forum_post_#{@forum_post.id}"), notice: "Successfully posted!"
else
  redirect_to @forum_thread, alert: "Unable to save your post"
end

end

def edit
end

def update
if @forum_post.update(forum_post_params)
redirect_to @forum_thread
else
render 'edit'
end
end

private

def set_forum_thread
  @forum_thread = ForumThread.find(params[:forum_thread_id])
  @forum_post = ForumPost.find(params[:id])
end

def forum_post_params
  params.require(:forum_post).permit(:body)
end

end

HTML



<%= div_for forum_post do %>

Posted by <%= forum_post.user.email %> <%= time_ago_in_words forum_post.created_at %> <%= link_to "Edit", :controller => "forum_posts", :action => "edit", :id => forum_post.id %>


<%= forum_post.body %>


<% end %>

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.