我已经在Heroku上部署了一个新版本的Rails 5应用程序,运行在cedar-14堆栈上。它在部署时没有预编译,因此我手动heroku run rake assets:precompile
。不过,我可以看到它包含旧资产,同时需要css
和js
个文件。
我的文件位于app/assets
,因此目录不在资源编译路径中。
application.rb
和production.rb
上的我的配置:
config.assets.compile = true
# I checked the environment variable, it responds to 'enabled',
# which would return true for the option.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Which I changed to expire old assets.
config.assets.version='1.1'
我试过这些,但他们没有工作:
$ heroku restart
$ heroku run rake assets:precompile
$ heroku run rake assets:clobber
这些奇怪之处在于它们不会影响heroku服务器中的资产,我使用$ heroku run ls public/assets
进行了检查。即使在$ rake assets:precompile
之后,即使这样说:
WRITING /app/public/assets/application-{VERY_LONG_HASH}.js
WRITING /app/public/assets/application-{VERY_LONG_HASH}.js.gz
WRITING /app/public/assets/application-{VERY_LONG_HASH}.css
WRITING /app/public/assets/application-{VERY_LONG_HASH}.css.gz
当我查看$ heroku run ls public/assets
时,我仍然看到旧资产留在那里。
编辑:我通过删除public/assets
中的所有本地资产,使用$ rake assets:clean && rake assets:precompile
重新编译它们并将这些资产包含在我的git
存储库中解决了这个问题。这是一个问题:
heroku不应该负责动态编译我的资产吗?我认为每次部署应用程序时都不应该编译我的资产。感谢。
答案 0 :(得分:2)
在本地
上运行@Controller
@RequestMapping("/tenant")
public class TenantController {
@Autowired
TenantDao tenantRepo;
@Autowired
MultiTenantConnectionProviderImpl multiTenantConnectionProviderImpl;
@SuppressWarnings("rawtypes")
@CrossOrigin
@RequestMapping(value = "/",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String registerTenant(@RequestBody Map map) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
Tenant tenant = mapper.convertValue(map, Tenant.class);
String tenantKey = tenant.getName().replaceAll("[^a-zA-Z]+", "").toLowerCase().trim();
Optional<Tenant> previouslyStored = tenantRepo.findByTenantKey(tenantKey);
String response="Sorry your company name ("+tenant.getName()+")"+" is already taken";
if (!previouslyStored.isPresent()) {
tenant.setTenantKey(tenantKey);
tenantRepo.save(tenant);
multiTenantConnectionProviderImpl.addTenant(tenantKey);
response = "Successfully registered, your key is " + tenantKey;
return response;
}
return new ObjectMapper().writeValueAsString(response);
}
}
下一个RAILS_ENV=production bundle exec rake assets:precompile
下一个git add .
下一个got commit -m"assets precompile"
在heroku上部署,你就完成了
答案 1 :(得分:0)
您需要先提交更改。
然后执行git push heroku yourbranch:master