所以在Rails3引擎中有自己的模型/控制器/视图,当然还有路由.现在的问题是:如何确保在应用程序路由之前(或之后)以及所有其他引擎上加载引擎路由?
这是我的Rails应用程序路由的示例:
match '*(path)', :to => 'foo_controller#bar_action'
Run Code Online (Sandbox Code Playgroud)
我的引擎:
match '/news', :to => 'bar_controller#foo_action'
Run Code Online (Sandbox Code Playgroud)
因此,默认情况下,引擎路由将在应用程序之后加载.这意味着由于我的应用程序中的全部路径,引擎路由无法访问.如何强制引擎路由首先(或最后)加载?
有没有办法确定结构是否持久?我开始为Ecto挖源,insert_or_update但运气不好,因为它碰到了一些私人方法。我想完成这样的事情:
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:whatever]
|> do_a_thing_on_unsaved_struct
end
defp do_a_thing_on_unsaved_struct(struct) do
case ARE_YOU_PERSISTED?(struct) do
:yes -> struct
:no -> do_things(struct)
end
end
Run Code Online (Sandbox Code Playgroud)
有可能吗,或者我正在做一些愚蠢的事情?
有趣的问题我得到了.我有一个使用arc-ecto处理文件上传的测试.在上传器模块中,我覆盖了storage_dir功能.在那里我做一个数据库调用来获取我正在上传的东西的父记录的id.在实践中很有效.
虽然测试很吓人.我猜这与文件保存是异步任务这一事实有关.因此,在保存文件之前完成测试.数据库连接已关闭,上传器错误消失.这是错误:
15:33:10.457 [error] Postgrex.Protocol (#PID<0.325.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.535.0> exited while client #PID<0.538.0> is still running with: shutdown
15:33:10.645 [error] Postgrex.Protocol (#PID<0.331.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.596.0> exited while client #PID<0.599.0> is still running with: shutdown
15:33:10.674 [error] Task #PID<0.599.0> started from #PID<0.598.0> terminating
** (DBConnection.ConnectionError) tcp recv: closed
(ecto) lib/ecto/adapters/postgres/connection.ex:115: Ecto.Adapters.Postgres.Connection.execute/4
(ecto) lib/ecto/adapters/sql.ex:243: Ecto.Adapters.SQL.sql_call/6
(ecto) lib/ecto/adapters/sql.ex:441: Ecto.Adapters.SQL.execute_or_reset/7
(ecto) lib/ecto/repo/queryable.ex:130: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:35: Ecto.Repo.Queryable.all/4
(ecto) lib/ecto/repo/queryable.ex:68: Ecto.Repo.Queryable.one/4
(pedal_app) lib/pedal_app/web/uploaders/photo_uploader.ex:31: PedalApp.Web.PhotoUploader.storage_dir/2
lib/arc/storage/local.ex:33: Arc.Storage.Local.build_local_path/3
lib/arc/storage/local.ex:27: Arc.Storage.Local.delete/3
(elixir) lib/task/supervised.ex:85: …Run Code Online (Sandbox Code Playgroud) 我看到很多与此相关的问题,但我无法找出解决方案.
这是在Django 1.4和Python 2.7上.
data是一个包含UTF8字符的字典.看到这一行:
render_to_response('application/app.html', data, context_instance=RequestContext(request))
获取模板以从中输出值data.
为什么它会爆炸,我该怎么做才能解决这个问题?
编辑:挖掘后,其中一部分data包含lxml.objectify.ObjectifiedElement.基本上是一个可以像普通字典一样查询的XML元素.它产生的值似乎是正确的unicode字符串,如下所示:u'\xae\u2020\xa5\xa8\u02c6\xf8'
这是完整的堆栈跟踪:
File "/web/mysite/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/web/mysite/current/api/views.py", line 163, in invoice
return render_to_response('application/app.html', data, context_instance=RequestContext(request))
File "/web/mysite/env/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 20, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/web/mysite/env/lib/python2.7/site-packages/django/template/loader.py", line 176, in render_to_string
return t.render(context_instance)
File "/web/mysite/env/lib/python2.7/site-packages/django/template/base.py", line 140, in render
return self._render(context)
File "/web/mysite/env/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
return self.nodelist.render(context)
File "/web/mysite/env/lib/python2.7/site-packages/django/template/base.py", line 823, …Run Code Online (Sandbox Code Playgroud) 在我的routes.rb 中,我想将 root_path 设置为 '/' 而不指定任何控制器或操作。那可能吗?
我试过了,root to: '/'但它在抱怨,没有指定控制器或操作。
更新信息:
我正在使用comfort-mexican-sofa CMS,我的root_path 应该转到cms 根路径。
目前我只是redirect_to '/'在我的控制器中使用并且这是有效的,但我认为使用root_path.
routes ruby-on-rails ruby-on-rails-4 comfortable-mexican-sofa