我的目标网页carmivore.com存在一个小问题。我想要的是页面上的表单(当用户订阅时)发布到相同的根URL(/),而不是/ subscribe。我可以在路由器中覆盖此行为,但在这种情况下,验证将停止工作。
路由器:
root :to => 'subscriptions#index'
post '/subscribe' => 'subscriptions#subscribe', :as => :new_subscription
控制器:
def index
@subscription = Subscription.new
end
def subscribe
@subscription = Subscription.new(params[:subscription])
if @subscription.save
redirect_to converted_path, notice: 'Thanks for signing up'
else
render :index
end
end
查看:
<%= form_for(@subscription, :url => new_subscription_path) do |f| %>