0

私はレールを使用してメーラーに取り組んでいますが、フィールドを表示する必要がある場所には何も表示されません。

ビューは次のとおりです。

<% simple_form_for(@message, :url => mailer_new_path) do |f| %>
  <%= f.error_notification%>
  <div class="inputs">
    <%=f.input :subject, :hint => "Write the subject here!"%>
    <%=f.input :body, :as => :text%>
  <div class="actions"%>
    <%=f.button :submit , 'Send Email', :class => "primary btn"%>
<% end%>

mailer_controller:

class MailerController < ApplicationController
  def new
    @message = Message.new
  end
end

メッセージ.rb:

class Message
  include MongoMapper::Document

  key :username, String
  key :subject, String
  key :body, String
  #validates_presence_of :username, :body
end

私が持っているルートでは:

get "mailer/new"
get "mailer/create"

誰か助けてくれませんか?前もって感謝します!

4

4 に答える 4

4

それ以外の:

<% simple_form_for(@message, :url => mailer_new_path) do |f| %>

あなたが持っている必要があります:

<%= simple_form_for(@message, :url => mailer_new_path) do |f| %>

違いはこれ<%=です。

Rails 2 では問題ありません。Rails 3/4=では、ブロックを渡す場合でも、ビュー ヘルパーを呼び出す前に配置する必要があります。

于 2013-08-08T09:49:16.893 に答える
1

<% %>任意の Ruby コード用ですが、結果を出力しません (if ステートメントなど)。

<%= %>Rubyコードの結果を出力するためのものです(例:モデルからの値)

<%- and -%>先頭と末尾の空白を抑制する

<%# %>ERBコメントです

于 2013-10-31T15:46:27.010 に答える
1

使用する

<%= simple_form_for(@message, :url => mailer_new_path) do |f| %>
于 2013-08-08T09:49:39.263 に答える
0

違いを見つける

<%= simple_form_for(@message, :url => mailer_new_path) do |f| %>
于 2013-08-08T09:49:21.113 に答える