使用current_user名称预填充表单 - Rails 4 + the_Comments

时间:2014-06-26 20:27:38

标签: ruby-on-rails forms

我想使用当前登录的用户(通过Devise + Twitter omniauth)预填充评论表单。但是我不知道我怎么能指责:标题要预先填充' current_user name'。

    = form_for Comment.new, remote: true, authenticity_token: true do |f|
      .error_notifier{ style: "display:none" }
      %label= t('the_comments.form.title')

      %p= f.text_field :title

      %label= t('the_comments.form.contacts')
      %p= f.text_field :contacts

      %label= t('the_comments.form.content')
      %p= f.text_area :raw_content

      %p.trap
        - TheComments.config.empty_inputs.each do |name|
          = text_field_tag name, nil, autocomplete: :off, tabindex: -1, id: nil

      = hidden_field_tag :tolerance_time, 0, id: nil, class: :tolerance_time

      = f.hidden_field :commentable_type, value: commentable.class
      = f.hidden_field :commentable_id,   value: commentable.id
      = f.hidden_field :parent_id, class: :parent_id

      %p
        = f.submit t('the_comments.form.create'), class: :btn
        = t('the_comments.form.thank_you')

我使用the_Comments作为评论的宝石。

解决了注释:value:current_user.name

1 个答案:

答案 0 :(得分:1)

您可以尝试以下代码

<%= f.text_field :title,value: current_user.name %>