다음과 같은 값을 보내려고하는 블로그 애플리케이션을 구축 중입니다.
그래서 내 쇼 액션 에서이 두 값을 내 게시물 컨트롤러의 편집 작업에 보내고 있지만 params [: commit] value ..을 수집 할 수 없습니다. 제 경우 승인을 위해 '승인'을 보내고 거부하면 보냅니다. '거절'하지만
[posts / show.html.erb]를 보내지 않습니다 .
<div id="post_content">
<h1 class="title"><%= @post.title %></h1>
<p class="date">
Submitted <%= time_ago_in_words(@post.created_at) %> Ago
<% if user_signed_in? %>
<%= link_to 'Edit', edit_post_path(@post) %> |
<%= link_to 'Delete', post_path(@post), method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to "approve",[:edit,@post] ,commit: "Approve"%>
<%= link_to "decline",[:edit,@post],commit: "decline" %>
<% end %>
</p>
<p class="body"><%= @post.body %></p>
<div id="comments">
<h2><%= @post.comments.count %> Comments</h2>
<%= render @post.comments %>
<h3>Add a comment:</h3>
<%= render "comments/form" %>
</div>
</div>
[posts_controller.rb]
class PostsController < ApplicationController
before_action :authenticate_user!
def index
@posts = Post.user_post(current_user).order('created_at DESC').paginate(:page => params[:page], :per_page => 5)
end
def new
@post = Post.new
end
def show
@post=find_params
end
def create
@post = Post.new(post_params)
@post.user = current_user
if @post.save
Post.upload(params[:post][:files],@post.id)
redirect_to @post
else
render 'new'
end
end
def edit
@post = find_params
puts "cccccccccc#{params[:commit]}"
Post.up(@post.id,params[:commit])
end
def update
@post = find_params
if @post.update(post_params)
redirect_to @post
else
render 'edit'
end
end
def destroy
@post = find_params
@post.destroy
redirect_to posts_path
end
private
def post_params
params.require(:post).permit(:title, :body)
end
def find_params
Post.find(params[:id])
end
end
이에 따라 link_to 태그를 변경하십시오.
<%= link_to "approve", edit_post_path(@post, commit: "Approve") %>
<%= link_to "decline", edit_post_path(@post, commit: "Decline" %>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다