加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – ActionMailer link_to显示操作失败并显示“缺

发布时间:2020-12-17 02:47:40 所属栏目:百科 来源:网络整理
导读:我正在尝试将一个链接显示为由rails action mailer呈现的视图中的动作. mailer.rb class Mailer ActionMailer::Base default from: "foo@bar.com" def catalog_download_request(email,catalog) @catalog = catalog mail({ to: email }) endend 的routes.rb
我正在尝试将一个链接显示为由rails action mailer呈现的视图中的动作.

mailer.rb

class Mailer < ActionMailer::Base
  default from: "foo@bar.com"

  def catalog_download_request(email,catalog)
    @catalog = catalog

    mail({
         to: email
    })
  end

end

的routes.rb

Rails.application.routes.draw do

  scope "(:locale)" do
    resources :catalogs,:path => I18n.t("routes.catalogs"),only: [:index,:show]
  end

end

development.rb:

config.action_mailer.default_url_options = { host: "http://localhost:3000" }
config.action_mailer.asset_host = "http://localhost:3000"

config.action_mailer.delivery_method = :smtp

config.action_mailer.smtp_settings = {
  address: "localhost",port: 1025
}

config.action_mailer.raise_delivery_errors = false

我打电话给邮件的模特:

class CatalogDownloadRequest < ActiveRecord::Base
  belongs_to :catalog

  after_create :send_mail

  private

  def send_mail
    Mailer.catalog_download_request(email,catalog).deliver
  end

end

这就是我在我看来尝试的内容:

<%= link_to @catalog %>

错误:

ActionView::Template::Error: No route matches {:action=>”show”,:controller=>”catalogs”,:format=>nil,:id=>nil,:locale=>#} missing required keys: [:id]

另一个尝试:

<%= link_to catalog_url(@catalog) %>

错误:

ActionView::Template::Error: No route matches {:action=>”index”}

我怀疑这种情况正在发生,因为我在路线上的语言环境范围.

如果我使用<%= link_to catalog_url(@catalog)%>在另一种观点中,它有效.

解决:

<%= link_to catalog_url(:id => @catalog.id),catalog_url(:id => @catalog.id) %>

解决方法

ActionView :: Template :: Error:No route匹配{:action =>“index”}的原因是:

link_to需要两个参数(text和url)(api).你只通过了一个.将文本作为第一个参数传递后,它将正常工作.

如果你真的想要,根据文档,你传递nil作为第一个参数,然后url作为第二个参数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读