I am trying to put a link to show the action in the view represented by 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
My model where I call in the mail:
class CatalogDownloadRequest < ActiveRecord::Base
belongs_to :catalog
after_create :send_mail
private
def send_mail
Mailer.catalog_download_request(email, catalog).deliver
end
end
What I tried in my opinion:
<%= link_to @catalog %>
Error:
ActionView :: Template :: Error: no route mappings {: action => "show" ,: controller => "catalogs" ,: format => nil ,: id => nil ,: locale => #} missing required keys: [: id]
Another attempt:
<%= link_to catalog_url(@catalog) %>
Error:
ActionView :: Template :: Error: no route matches {: action => "index"}
I suspect this is due to my locality on the routes.
If I use <%= link_to catalog_url(@catalog) %>in a different view, it works.
It is decided:
<%= link_to catalog_url(:id => @catalog.id), catalog_url(:id => @catalog.id) %>