在 Rails 3 中的布局之间共享资源

发布于 2024-11-17 12:52:05 字数 714 浏览 1 评论 0原文

好的,我已经在 Rails 中设置了我的邮件程序,它工作得很好,但我想进行一个新操作(或者可能只是一个视图?)以在灯箱中显示一个精简的联系表单。我可以做得很好,但它会使用我不想要的默认布局。所以我

render :layout => 'lightbox'

在操作中添加了:,以便我可以使用新的布局。不幸的是,这似乎阻止了我对模型的访问,因为当灯箱弹出时我收到此错误

undefined method `model_name' for NilClass:Class
 #on this line
<% form_for @contact, :url => {:action => "create"}, :html => {:method => :post} do |f| %>

因此,通过使用不同的布局,我无法使用我在此处的路线中设置的资源:

  resources :contacts, :only => [:new, :create], :as => :contacts
  #Im passing in a name to the email form
  match "contacts/direct/:name" => "contacts#direct", :as => :direct_email

我希望这是有道理的。但我该怎么办呢?

OK, so Ive set up my mailer in Rails which works fine, but I wanted to make a new action (or maybe just a view?) to have a slimmed down contact form in a lightbox. I can do that all fine and dandy but it would use the default layout which I dont want. So I added:

render :layout => 'lightbox'

to the action so that I could use a new layout. Unfortunately that seems to block off my access to the model as I get this error when the lightbox pops up

undefined method `model_name' for NilClass:Class
 #on this line
<% form_for @contact, :url => {:action => "create"}, :html => {:method => :post} do |f| %>

So by using a different layout I cant use the resources I set up in my routes which is here:

  resources :contacts, :only => [:new, :create], :as => :contacts
  #Im passing in a name to the email form
  match "contacts/direct/:name" => "contacts#direct", :as => :direct_email

I hope that made sense. But what do I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文