导航到 new_mailer 时,ActionMailer before_action 正在传递 img src
ActionMailer before_action is being passed img src's when navigating to new_mailer
通知控制器:
class NotificationsController < ApplicationController
before_action :set_notification, only: [:show, :edit, :update, :destroy]
# GET /notifications
# GET /notifications.json
def index
@notifications = Notification.all
end
# GET /notifications/1
# GET /notifications/1.json
def show
end
# GET /notifications/new
def new
@notification = Notification.new
end
.
.
.
private
# Use callbacks to share common setup or constraints between actions.
def set_notification
@notification = Notification.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def notification_params
params.require(:notification).permit(:name, :email, :subject, :text)
end
end
单击 new_notification_path link 时,所有这些都会打印到控制台
Started GET "/notifications/new" for ::1 at 2017-04-06 23:41:03 -0400
Processing by NotificationsController#new as HTML
Started GET "/notifications/legal2.jpg" for ::1 at 2017-04-06 23:41:03 -0400
Started GET "/notifications/photo1.jpg" for ::1 at 2017-04-06 23:41:03 -0400
Processing by NotificationsController#show as JPEG
Processing by NotificationsController#show as JPEG
Parameters: {"id"=>"legal2"}
Rendering notifications/new.html.erb within layouts/application
Parameters: {"id"=>"photo1"}
Notification Load (0.5ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."id" = ? LIMIT ? [["id", 0], ["LIMIT", 1]]
Notification Load (0.0ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."id" = ? LIMIT ? [["id", 0], ["LIMIT", 1]]
Rendered notifications/_form.html.erb (1.5ms)
Completed 404 Not Found in 15ms (ActiveRecord: 0.5ms)
Completed 404 Not Found in 4ms (ActiveRecord: 0.0ms)
Rendered notifications/new.html.erb within layouts/application (14.9ms)
ActiveRecord::RecordNotFound (Couldn't find Notification with 'id'=legal2):
ActiveRecord::RecordNotFound (Couldn't find Notification with 'id'=photo1):
app/controllers/notifications_controller.rb:69:in `set_notification'
app/controllers/notifications_controller.rb:69:in `set_notification'
Completed 200 OK in 198ms (Views: 186.0ms | ActiveRecord: 0.0ms)
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (2.0ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (2.0ms)
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.5ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (1476.0ms)
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (1644.6ms)
为什么会调用 NotificationsController#show 并以两个照片源作为参数,如果仅调用 'new' 操作,为什么会调用 set_notification?
视图生成错误。也许您正在尝试根据直接路径设置图像。
使用 rails 资产辅助方法,例如
<%= image_tag asset_path("myimage.jpg"), size: '200x200', class: 'img-responsive' %>
它将使用文件夹 (app/assets/images) 中图像的资产路径,并将在开发和生产中使用编译资产)
希望这对您有所帮助...
通知控制器:
class NotificationsController < ApplicationController
before_action :set_notification, only: [:show, :edit, :update, :destroy]
# GET /notifications
# GET /notifications.json
def index
@notifications = Notification.all
end
# GET /notifications/1
# GET /notifications/1.json
def show
end
# GET /notifications/new
def new
@notification = Notification.new
end
.
.
.
private
# Use callbacks to share common setup or constraints between actions.
def set_notification
@notification = Notification.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def notification_params
params.require(:notification).permit(:name, :email, :subject, :text)
end
end
单击 new_notification_path link 时,所有这些都会打印到控制台
Started GET "/notifications/new" for ::1 at 2017-04-06 23:41:03 -0400
Processing by NotificationsController#new as HTML
Started GET "/notifications/legal2.jpg" for ::1 at 2017-04-06 23:41:03 -0400
Started GET "/notifications/photo1.jpg" for ::1 at 2017-04-06 23:41:03 -0400
Processing by NotificationsController#show as JPEG
Processing by NotificationsController#show as JPEG
Parameters: {"id"=>"legal2"}
Rendering notifications/new.html.erb within layouts/application
Parameters: {"id"=>"photo1"}
Notification Load (0.5ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."id" = ? LIMIT ? [["id", 0], ["LIMIT", 1]]
Notification Load (0.0ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."id" = ? LIMIT ? [["id", 0], ["LIMIT", 1]]
Rendered notifications/_form.html.erb (1.5ms)
Completed 404 Not Found in 15ms (ActiveRecord: 0.5ms)
Completed 404 Not Found in 4ms (ActiveRecord: 0.0ms)
Rendered notifications/new.html.erb within layouts/application (14.9ms)
ActiveRecord::RecordNotFound (Couldn't find Notification with 'id'=legal2):
ActiveRecord::RecordNotFound (Couldn't find Notification with 'id'=photo1):
app/controllers/notifications_controller.rb:69:in `set_notification'
app/controllers/notifications_controller.rb:69:in `set_notification'
Completed 200 OK in 198ms (Views: 186.0ms | ActiveRecord: 0.0ms)
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (2.0ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (2.0ms)
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.5ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (1476.0ms)
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (1644.6ms)
为什么会调用 NotificationsController#show 并以两个照片源作为参数,如果仅调用 'new' 操作,为什么会调用 set_notification?
视图生成错误。也许您正在尝试根据直接路径设置图像。 使用 rails 资产辅助方法,例如
<%= image_tag asset_path("myimage.jpg"), size: '200x200', class: 'img-responsive' %>
它将使用文件夹 (app/assets/images) 中图像的资产路径,并将在开发和生产中使用编译资产)
希望这对您有所帮助...