我对 Rails 还比较陌生,在这里查看了许多类似的问题,但到目前为止没有一个对我有帮助。所以...我有一个表格,我想发送一封简单的电子邮件。它以 Bootstrap 模式弹出,如下所示:
.form-horizontal
= form_tag :url => { :action => :share_event }, remote: true, html: {"data-type" => :json} do
.control-group
= label_tag :to
= text_field_tag :to
.control-group
= label_tag :from
= text_field_tag :from
.control-group
= label_tag :subject
= text_field_tag :subject
- hidden_field_tag :event_url, :value => url
.actions
= submit_tag 'share event', :class => "btn btn-mini submit"
在我的控制器中:
def share_event
@to = params[:to]
@from = params[:from]
@subject = params[:subject]
@url = params[:url]
respond_to do |format|
EventMailer.share_event(@to, @from, @subject, @url).deliver
redirect_to events_path, notice: 'Event sent'
end
end
EventMailer.share_event(@to, @from, @subject, @url).deliver
end
路线:
resources :events do
post :share_event, :on => :collection
end
问题是当我提交它时使用“创建”操作而不是“share_event”。我尝试了很多方法,但它继续使用“创建”。以下是日志的摘录:
Started POST "/events?html%5Bdata-type%5D=json&remote=true&url=share_events_path" for 41.134.48.225 at 2012-11-06 15:34:25 +0100
Processing by EventsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"7/6pg9XX/N09qUB+SUlWOdpCsgPOAiXM+nC+mq6VtKE=", "to"=>"to@example.com", "from"=>"from@example.com", "subject"=>"gfh", "event_url"=>"{:value=>\"http://events.example.com/events/3\"}", "commit"=>"share event »", "html"=>{"data-type"=>"json"}, "remote"=>"true", "url"=>"share_events_path"}
任何帮助/建议将不胜感激。
非常感谢!