我正在开发的应用程序有一个功能,用户可以单击链接向朋友发送电子邮件。我不想保存朋友信息(第一个、最后一个、电子邮件),所以我尝试执行以下操作(在 users_controller.rb 中):
def send_invitation_to_friend
if params[:commit] == 'Email Invitation'
@friend_info = params[:friend_info]
EventMailer.deliver_send_invitation_to_friend(@friend_info).deliver
redirect_to_root_url
end
render 'send_invitation_to_friend'
end
在我的意见/用户/send_invitation_to_friend_html.erb 中,我有:
<div class="pagetopper"></div>
<% if !user_signed_in? %>
<% redirect_to_root_url %>
<% end %>
<%= form_for @friend_info, :url => {:controller => :users, :action => :send_invitation_to_friend} do |f| %>
<div class="field-section-header">
About The Person You're Inviting
</div>
<div class="control-group">
<div class="control-label"><%= f.label :first, FIRST_STR %></div>
<div class="controls"><%= f.text_field :first, :class => "request-text-line" %></div>
</div>
<div class="control-group">
<div class="control-label"><%= f.label :last, LAST_STR %></div>
<div class="controls"><%= f.text_field :last, :class => "request-text-line" %></div>
</div>
<div class="control-group">
<div class="control-label"><%= f.label :email, EMAIL_STR %></div>
<div class="controls"><%= f.email_field :email, :class => "request-text-line" %></div>
</div>
<div class="control-group">
<div class="controls"><%= submit_tag 'Email Invitation', :class => "submit_button" %></div>
</div>
我收到以下错误:
undefined method `model_name' for NilClass:Class
Extracted source (around line #7):
4: <% redirect_to_root_url %>
5: <% end %>
6:
7: <%= form_for @friend_info, :url => {:controller => :users, :action => :send_invitation_to_friend} do |f| %>
我没有friend_info的模型和迁移,因为我不想保存此信息,那么我如何显示表单?