我是 Ruby on Rails 的新手。我的问题可能听起来很奇怪,但我被困住了。我有一个在 html 页面上创建的表单。我用过render partial
,但这种形式没有创造任何价值。这是我的控制器代码。
控制器.rb
before_filter :signed_in_user, only: [:create, :destroy]
def create
@suppliers = current_user.suppliers.build(params[:supplier_name])
if @suppliers.save
flash[:success] = "Supplier Saved!"
redirect_to 'suppliers/home'
else
render 'suppliers/home'
end
end
def destroy
end
def home
if signed_in?
@supplier = current_user.suppliers.build
@feed_items = current_user.feed.paginate(page: params[:page])
end
end
我的home.html.erb
<div class="row">
<aside class="span4">
<section>
<%= render 'suppliers/suppliers_form' %>
</section>
</aside>
<div class="span8">
<h3>Micropost Feed</h3>
<%= render 'suppliers/feed_supplier' %>
</div>
</div>
我的_supplier_form.html.erb是
<%= form_for(@supplier) do |f| %>
<div>
<%= f.text_field :supplier_name, placeholder: "Add new Supplier" %>
</div>
<%= f.submit "Add", class: "btn btn-large btn-primary" %>
<% end %>
我的_feed_supplier.html.erb是
<% if @feed_items.any? %>
<ol class="microposts">
<%= render partial: 'suppliers/feed_item', collection: @feed_items %>
</ol>
<%= will_paginate @feed_items %>
<% end %>
我的_feed_item.html.erb是
<li id="<%= feed_item.id %>">
<span class="user">
<%= link_to feed_item.user.name, feed_item.user %>
</span>
<span class="content"><%= feed_item.supplier_name %></span>
</li>
请引导我走向正确的方向,如果还有其他需要,请询问。提前致谢
注意:所有提到的文件都在同一个文件夹中,即供应商。除了控制器文件