如何在erb模板中显示自定义设计参数

时间:2018-09-29 04:31:56

标签: ruby-on-rails devise

<%= simple_form_for [ @user ,@tweet], id: "form-submit" do |f| %>
   <%= f.input :content, label: "Tweet" %>
   <%= f.button :submit, class: "btn btn-danger" %>
   <% end %>

   <br>

<% @tweets.each do |tweet|  %>
  <ul>
    <li>
      <%= tweet.created_at.strftime("%B %d %Y, %l:%M%P") %> <br>
      <%= tweet.content %>
      <%= tweet.user.email %>

    </li>
  </ul>
<% end %>

我正在制作一个Twitter克隆。我正在尝试在用户的推文旁边显示用户名。我正在使用devise,我已经做到了,所以用户在登录时输入名字,姓氏和用户名。但是,它们在Rails控制台上显示为nil,不确定是什么问题,因为我认为一切我添加到应用程序控制器中是正确的。它在我执行tweet.user.email时有效。

<div class="form-inputs">
  <%= f.input :first_name, required: true, autofocus: true , input_html: { autocomplete: "First Name" }%>
  <%= f.input :last_name, required: true, autofocus: true , input_html: { autocomplete: "Last Name" }%>
  <%= f.input :username, required: true, autofocus: true , input_html: { autocomplete: "Username" }%>
  <%= f.input :email, required: true, autofocus: true , input_html: { autocomplete: "email" }%>
  <%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), input_html: { autocomplete: "new-password" } %>
  <%= f.input :password_confirmation, required: true, input_html: { autocomplete: "new-password" } %>
</div>

我的应用程序控制器是:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :authenticate_user!
  before_action :configure_permitted_parameters, if: :devise_controller?

  def configure_permitted_parameters
    # For additional fields in app/views/devise/registrations/new.html.erb
    devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :username])

    # For additional in app/views/devise/registrations/edit.html.erb
    devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :username])
  end
end

0 个答案:

没有答案