class UserPreview < ActionMailer::Preview
# Accessible from http://localhost:3000/rails/mailers/notifier/welcome_email
def welcome_email
UserMailer.welcome_email(User.first)
end
end
我有这个简单的邮件预览使用Rails 4.1。
如果我注释掉了,我的routes.rb文件中的所有路由都只留下这个,则邮件预览会工作:
MyTestApp::Application.routes.draw do
我想编写一个插件,它需要做一个猴子补丁来在rails应用程序routes.rb中定义的所有路由上添加一个约束。
我尝试在我的猴子补丁中执行下面的代码,但这不起作用。正确的方法是什么?
Rails.configuration.to_prepare do
RedmineApp::Application.routes.routes.each do |route|
route.app.constraints << lambda{ |request| request.subdomains.first == 'admin' }
end
end
在我的路由中,我添加了这两条路由
match '/:controller(/:action(/:id))', :controller => /admin\/[^\/]+/
match '/:controller(/:action(/:id))'
当我转到无效路由时,就会给我
The action 'dashboard1' could not be found for Admin::AdminController
我在routes.rb文件的末尾添加了以下行
match "*path" => redirect("
我开始在所有模型的id字段中使用Postgres类型。它工作得很好,在Rails 4中得到了支持(大部分情况下):
create_table :users, id: :uuid do |t|
# ...
end
问题是,如果您试图找到id为X的行,但X不是格式正确的UUID字符串,Postgres将引发错误。
> User.find "3ac093e2-3a5e-4744-b49f-117b032adc6c"
ActiveRecord::RecordNotFound # good, will cause a 404
> User.find "foobar
我需要接下来的三条路线:
get "", to: redirect("/#{I18n.locale}")
get '/:locale/', to: "home#index"
get "/*path", to: redirect("/#{I18n.default_locale}/%{path}", status: 302), constraints: {path: /(?!(#{I18n.available_locales.join("|")})\/).*/}, format: fal
我正在尝试从我的rails应用程序的公共文件夹中提供react应用程序。我正在构建js文件,并将其放入公共文件夹中。当我转到应用程序的根目录时,我可以看到js和我的index.html页面已经加载。然而,当我尝试访问页面时,比如/landing,我得到了一条Rails中找不到的404路由。我不明白为什么react路由器不起作用。这一切都在dev上工作,我在第二个服务器上为react应用程序提供服务,我只在生产中遇到这个问题。有什么建议吗?
index.js
import React from 'react';
import ReactDOM from 'react-do
我有一个rails应用程序在开发模式下工作,路由配置如下:
scope module: :web do
resources :locations
end
constraints subdomain: "api" do
scope module: :api do
resources :locations
end
end
这在启动rails服务器和分别使用www.lvh.me:3000和api.lvh.me:3000时起作用。但是,在使用apache和passenger在生产中运行时,这会失败,在访问任何域时都会出现Actio
在我正在做的一个Rails3.2应用程序中,我想创建一些特定于移动设备的视图(和操作处理)。所以我创建了一个名为mobile的命名空间。
namespace :mobile do
resources :sessions
resources :areas
end
例如,如果用户使用手机进入登录页面,我希望使用我为该名称空间创建的控制器和视图。
所以现在我有两种不同的登录方式:
new_mobile_session GET /mobile/sessions/new(.:format) mobile/sessions#new
和
new_session G
我正在使用Angular和Rails编写应用程序。我的ApplicationController中有回退
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :intercept_html_requests
private
def intercept_html_requests
render('pages/index') if request.format == Mime::HTML
end
end
和像这样的路由器
我正在开发rails应用程序,并遇到了这样的问题。
我有movies_controller.rb,在这里我定义了这些操作和路线:
Prefix Verb URI Pattern Controller#Action
movies GET /movies(.:format) movies#index
POST /movies(.:format) movies#create
new_movie GET