混亂的原因是在一天的開始我所有的表格都在工作。在設計項目後,我的所有表單都停止工作。當我全部提交時,交易在控制檯中工作,除了社區創建。 如果您需要更多的代碼來了解,請詢問。我真的很困惑我的表格
社區控制器
def create
current_user
@community = Community.new(community_params)
@community.user_id = session[:user_id]
if @community.save
flash[:notice] = "Post Created"
else
flash[:alert] = "Error post not created"
end
redirect_to @community
end
def new
current_user
@community = Community.new
end
社區新視點
<%= render partial: 'users/user_profile' %>
<br>
<h1 class="create_new_community">CREATE A NEW COMMUNITY</h1>
<form class="community_form">
<%= form_for @community do |f| %>
<div class="title">
<%= f.text_field :title, placeholder: "Title of Community", rows: 40, class: "community_title" %>
</div>
<div class="text_field">
<%= f.text_area :bio, placeholder: "Enter Community bio here...", :cols => 90, :rows => 10, :class => 'community_text_field' %>
</div>
<div class="submit_post">
<%= f.submit class: "CREATE NEW COMMUNITY" %>
</div>
<% end %>
</form>
評論控制器
def create
@comment = @commentable.comments.new comment_params
@comment.save
redirect_to @commentable
end
def new
@comment = Comment.new
end
個評論 - 視圖 - 新
<p>
<h2 class="comment_header">Comments</h2>
<% commentable.comments.reverse.each do |comment| %>
<div id="well">
<div class='image_name'>
<%= image_tag comment.user.avatar.url(:medium), class: 'comment_image' %>
<span class='comment_user_name'><%= comment.user.first_name %></span>
</div>
<div class="arrow_box">
<ul class'messagebox'><%= comment.text %> -
<span class='comment_time'><%= time_ago_in_words(comment.created_at) %> <strong>ago</strong></span>
</ul>
</div>
</div>
<hr>
<% end %>
</p>
對於所有那些在解決這個錯誤或方向指向調試錯誤提供幫助,謝謝了很多。也感謝所有查看此頁面的人。
-Steven
編輯 提交評論時,在我的控制檯和發現錯誤
Started POST "/communities/14/comments" for 127.0.0.1 at 2015-11-09 13:08:23 -0500
Processing by Communities::CommentsController#create as JS
Parameters: {"utf8"=>"✓", "comment"=>{"text"=>"hi"}, "commit"=>"new_comment_button", "community_id"=>"14"}
Community Load (0.1ms) SELECT "communities".* FROM "communities" WHERE "communities"."id" = ? LIMIT 1 [["id", 14]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 11]]
(0.1ms) begin transaction
SQL (0.4ms) INSERT INTO "comments" ("commentable_id", "commentable_type", "created_at", "text", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?) [["commentable_id", 14], ["commentable_type", "Community"], ["created_at", "2015- 11-09 18:08:23.804413"], ["text", "hi"], ["updated_at", "2015-11-09 18:08:23.804413"], ["user_id", 11]]
(0.6ms) commit transaction
Redirected to http://localhost:3000/communities/14
Completed 302 Found in 6ms (ActiveRecord: 1.2ms)
請想出一個更具描述性的,有用的稱號。 –
您可以在提交表單時顯示日誌嗎? –
@KMRakibulIslam我添加了我在控制檯中看到的內容,一旦我點擊提交我的評論表單。 –