简单的形式 - 类似Reddit的网站

时间:2018-01-16 21:11:39

标签: ruby-on-rails ruby simple-form

我完成了搜索,发现这个主题很接近,我如何制作简单的表格,我太新了,无法完全理解 我在看什么。

答案如下:

第1步     rails生成simple_form:install --bootstrap(我在添加Gem并运行Bundle Install后做了)

第2步 告诉我添加包装器(不确定我是否需要完成此步骤)

第3步 修改simple_form并有这个例子:

<%= simple_form_for(@contact, url: supplier_contacts_path, html: { class: 
'form-horizontal' }) do |f| %>
<div class="form-inputs">
<%= f.input :c_regular,wrapper: :horizontal_input_group do %>
<span class="input-group-addon">$</span>
<%= f.input_field :c_regular, :label => "Regular",class: "form-control" %>
<% end %>
</div>
<% end %>  

我的代码如下(views / comments / show.html.erb):

<div id="comments">
  <%= render :partial => @link.comments %>
</div>

<%= simple_form_for(@link, html {class: 'form-horizontal' })  do |f| %>  
<div class="field">  
  <%= f.text_area :body, size: "60x12" %>
</div>  
<%= f.submit "Add Comment", class: 'btn btn-primary" %>
<% end %>  

这是我的部分内容(views / comments / _comments.html.erb):

<%= div_for(comment) do %>
<div class="comments_wrapper clearfix">
<div class="pull-left">
<p class="lead"><%= comment.body %></p>
<p><small>Submitted <strong><%= time_ago_in_words(comment.created_at) %> 
ago</strong> by
<%= comment.user.email %></small></p>
</div>
<div class="btn-group pull-right">
<% if comment.user == current_user %>
<%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you 
sure?' }, class: "btn btn-sm btn-default" %>
<% end %>
<% end %>
</div>
<% end %>    

0 个答案:

没有答案