我觉得我缺少一些简单的东西。我建立了一个MailChimp邮件列表,我试图让注册按钮正常工作,但得到提交错误。我已经将它路由回控制器中create方法的根目录,但它不起作用。没有路由匹配[邮政]“/” - 试图设置邮件列表
signup.rb
class Signup < ActiveRecord::Base
validates_presence_of :email
validates_format_of :email, :with => /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i
def subscribe
mailchimp = Gibbon::API.new
result = mailchimp.lists.subscribe({
:id => ENV['MAILCHIMP_LIST_ID'],
:email => {:email => self.email},
:double_optin => false,
:update_existing => true,
:send_welcome => true
})
Rails.logger.info("Subscribed #{self.email} to MailChimp") if result
end
end
signups_controller.rb
class SignupsController < ApplicationController
def new
@signup = Signup.new
end
def create
@signup = Signup.new(secure_params)
if @signup.valid?
redirect_to root_path
else
render :new
end
end
private
def secure_params
params.require(:signup).permit(:email)
end
end
的routes.rb
Rails.application.routes.draw do
root 'pages#index'
get '/about' => 'pages#about'
get '/tour' => 'pages#tour'
get '/music' => 'pages#music'
resources :signups, only: [:new, :create]
end
我可以把routes.rb中怎么得到这个文章?这里是我的耙路线输出...
Prefix Verb URI Pattern Controller#Action
root GET/ pages#index
about GET /about(.:format) pages#about
tour GET /tour(.:format) pages#tour
music GET /music(.:format) pages#music
signups POST /signups(.:format) signups#create
new_signup GET /signups/new(.:format) signups#new
在此先感谢!
你究竟如何得到这个错误?你能向我们展示视图形式吗? – dgilperez 2015-02-09 03:23:31
另外,你既没有保存注册,也没有调用''#subscribe'',顺便说一句。 – dgilperez 2015-02-09 03:24:29
<%= simple_form_for:signup do | f | %> <%= f.input:电子邮件,标签:假,:占位符=> '[email protected]' %>
\t \t \t <%= f.submit '注册',:类=> 'BTN BTN-危险' %> \t \t \t <% end %> \t \t \t
– MCHLWRRN 2015-02-09 03:45:53