在 Rails 3 中的布局之间共享资源
好的,我已经在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论