我有rails app(source)进行日程安排。我正在尝试在轮班视图和邮件消息之间重用template for shifts tables。
我想删除邮件的链接,但是逻辑有问题。我目前的HAML是:
%table#shift-table
%tr
%th Start
⋮
%th Task
- if defined? params
%th.options
- @shifts.each do |shift|
%tr
%td= shift.start
⋮
%td= link_to_if(defined? params, shift.task.name, shift) if shift.task
- if defined? params
%td
= link_to 'Show', shift, class: [:btn, 'btn-default']
- if defined? can? and can? :update, shift
= link_to 'Edit', edit_shift_path(shift), class: [:btn, 'btn-default']
- if defined? can? and can? :destroy, shift
= link_to 'Delete', shift, :method => :delete, :data => { :confirm => 'Are you sure?' }, class: [:btn, 'btn-default']
邮件程序中defined? params
为true
,因此无效。当我尝试params.nil?
或params[:controller]
时,我得到:
undefined method `params' for #<ScheduleMailer:0xae5e520>
我应该提一下,我是从rake task发送电子邮件。
答案 0 :(得分:0)
您想知道视图是否从控制器呈现
# Idiom for setting undefined value
- params = params rescue {}
...
- if params[controller]
或者您可以查看是否