我使用Phoenix内置的gen.HTML生成一个简单的视图,但它不起作用
<%= link "Delete", to: event_path(@conn, :delete, event), method: :delete, data: [confirm: "Are you sure?"], class: "btn btn-danger btn-xs" %>
Run Code Online (Sandbox Code Playgroud)
在页面上它看起来像是假设,但它只是附加#到地址
生成结构:
<form action="/event/1" class="link" method="post">
<input name="_method" type="hidden" value="delete">
<input name="_csrf_token" type="hidden" value="BwUSGQcDO1MwPzw0HBgqLnshHn8HNgAAnCTjuMt0viFshobX4XM/dQ==">
<a class="btn btn-danger btn-xs" data-confirm="Are you sure?" data-submit="parent" href="#">Delete</a>
</form>
Run Code Online (Sandbox Code Playgroud)
我错过了js导入的排序吗?我也可以通过浏览器下载:
//This is being downloaded as phoenix_html.js
// Although ^=parent is not technically correct,
// we need to use it in order to get IE8 support.
var elements = document.querySelectorAll('[data-submit^=parent]')
var len = elements.length
for (var …Run Code Online (Sandbox Code Playgroud) 我想知道Play-Scala中的@Inject注释是如何工作的.它显然注入了依赖,但我很好奇它是如何工作的.当我在类扩展控制器上使用它并将路由生成器设置为injectroutesgenerator时,它似乎从这些类中自动创建对象,但是如何在其他上下文中使用它?
我试过了:
@Inject val mailer: MailerClient = null
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.@Inject的东西(mailerClient,WS ets.)是否有任何可能直接与值,而不是控制器类?
燮,
我正在尝试编码一些嵌套的Ecto模型,但我遇到了一个问题.我意识到我不能对卸载的模型进行编码,我希望有可能只选择一个结构而不加载休息,同时有可能选择整个树.
我用defimpl的方法,例如:
defimpl Poison.Encoder, for: Hangman.MasterCat do
def encode(page, _options) do
%{
id: page.id,
name: page.name,
categories: page.categories
} |> Poison.Encoder.encode([])
end
end
defimpl Poison.Encoder, for: Hangman.Category do
def encode(category, _options) do
IO.inspect(category.words)
%{
id: category.id,
name: category.name,
words: category.words
} |> Poison.Encoder.encode([])
end
end
defimpl Poison.Encoder, for: Hangman.Word do
def encode(page, _options) do
%{
content: page.content
} |> Poison.Encoder.encode([])
end
end
Run Code Online (Sandbox Code Playgroud)
这适用于整个结构,但它不适用于仅选择MasterCats并且它会产生这样的错误.
cannot encode association :categories from Hangman.MasterCat to JSON because the association was not loaded. Please make …Run Code Online (Sandbox Code Playgroud) 我试图在Ecto Postgres做2场独特的约束.到目前为止,我设法做到了:
在迁移中:
create unique_index(:presences, [:event_id, :user_id], name: :special_event_user)
Run Code Online (Sandbox Code Playgroud)
变更:
def changeset(presence, params \\ :empty) do
presence
|> cast(params, @required_fields, @optional_fields)
|> foreign_key_constraint(:user_id)
|> foreign_key_constraint(:event_id)
|> unique_constraint(:event_id, name: :special_event_user)
end
Run Code Online (Sandbox Code Playgroud)
也尝试过:
|> unique_constraint(:special_event_user)
Run Code Online (Sandbox Code Playgroud)
但我一直在:
If you would like to convert this constraint into an error, please
call unique_constraint/3 in your changeset and define the proper
constraint name. The changeset has not defined any constraint.
Run Code Online (Sandbox Code Playgroud)
我以为我已经做过了.有什么建议?
编辑:
行动:
def assign(conn, %{"event" => event_id}) do
case Integer.parse(event_id) do
{val, _ } -> …Run Code Online (Sandbox Code Playgroud) 我想知道是否有可能找到所有具有特定模块实现的模块?
我有一个简单的协议:
defprotocol Ep.PerformTest do
@doc "Should return tupple {out, time}"
def test(struct)
end
Run Code Online (Sandbox Code Playgroud)
并且很少有具有此协议实现的模块:
defmodule Ep.Test.Rexcpp do
defstruct [:input, :code, :output]
def displayName(), do: "Rextester C++"
defimpl Ep.PerformTest, for: Ep.Test.Rexcpp do
def test(struct) do
end
end
end
Run Code Online (Sandbox Code Playgroud) 苏普,
我正在尝试在 Play2.4 Scala 中为我的项目设置环境变量。我已经在 Intellij 的运行配置中设置了变量。
令人烦恼的是 Scala 似乎没有看到这些。
我不断收到未为我使用环境变量的键指定的配置错误。
当我启动应用程序时,这些显示在控制台中:
"C:\Program Files\Java\jdk1.8.0_25\bin\java" -Dfile.encoding=UTF8 -DMAIL_PORT=587 -DDB_URI=mongodb://uri -Djline.terminal=none -Dsbt.log.noformat=true -Dsbt.global.base=C:\Users\Haito\AppData\Local\Temp\sbt-global-plugin7stub -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M -classpath C:\Users\Haito\.IntelliJIdea14\config\plugins\Scala\launcher\sbt-launch.jar xsbt.boot.Boot "project root" ~run
Run Code Online (Sandbox Code Playgroud)
以及配置文件:
mongodb.uri = ${?DB_URI}
play.mailer {
host=${?MAIL_HOST}
port=${?MAIL_PORT}
ssl=false
tls=true
user=${?MAIL_USERNAME}
password=${?MAIL_PASSWD}
debug=false
mock=false
}
Run Code Online (Sandbox Code Playgroud)
我不断收到这些:
Missing configuration key 'mongodb.db'!
Run Code Online (Sandbox Code Playgroud)
当然我的问题不是我的 mongo 驱动程序。我的问题是配置没有提供环境变量。Mailer 也使用环境变量进行配置。当我粘贴除 之外的实际 URI 时,${?DB_URI}它会起作用。
建造:
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
libraryDependencies ++= Seq(
"org.reactivemongo" %% "play2-reactivemongo" % "0.11.2.play24" …Run Code Online (Sandbox Code Playgroud) 我正在与Android做一些工作,并想用它来测试Retrolambda.但不幸的是我遇到了一个问题.
我有一个Dialog类,它将Consumer作为参数:
public class AuthDialog extends Dialog {
public static final String SERVER_URL = "http://cohhgas.ddns.net/auth";
private Consumer<UserCredentials> onSuccess;
public AuthDialog(Context context, Consumer<UserCredentials> onSuccess) {
super(context);
this.onSuccess = onSuccess;
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个使用它的活动:
public class MainActivity extends AppCompatActivity {
public static final String CREDENTIALS = "sharedPrefsCredentials";
GiveAway giveAway;
SharedPreferences sharedpreferences;
public MainActivity() {
EventBus.getDefault().register(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final AuthDialog auth_dialog;
auth_dialog = new AuthDialog(MainActivity.this, userCredentials -> Log.d("cool", "works"));
auth_dialog.show();
TextView textView = new TextView(MainActivity.this);
textView.setOnClickListener((view) -> …Run Code Online (Sandbox Code Playgroud) Sup,我正在学习Ecto,我正在尝试将关联记录插入到另一个表中.它有点工作,因为正在插入记录但是外键字段是空的.
码:
parent = Repo.get(Hangman.MasterCat, parent_id)
changeset = build(parent, :categories)
|> Category.changeset( params)
IO.inspect(changeset)
if changeset.valid? do
Repo.insert(changeset)
json conn, ResponseUtils.jsonResponse(true)
else
json conn, ResponseUtils.jsonResponse(false,["parents doesn't exist"])
end
Run Code Online (Sandbox Code Playgroud)
检查变更集
%Ecto.Changeset{action: nil, changes: %{name: "Kategory 1"}, constraints: [],
errors: [], filters: %{},
model: %{__meta__: #Ecto.Schema.Metadata<:built>, __struct__: Hangman.Category,
id: nil, inserted_at: nil, master_cat_id: 1,
mastercat: #Ecto.Association.NotLoaded<association :mastercat is not loaded>,
mastercat_id: nil, name: nil, updated_at: nil,
words: #Ecto.Association.NotLoaded<association :words is not loaded>},
optional: [], opts: [], params: %{"name" => "Kategory 1"}, repo: …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习Phoenix的Form系统,包括Ecto.Model,但我遇到了一个我无法通过的问题.我创建了一个表单:
<div class="jumbotron">
<%= form_for @changeset, user_path(@conn, :create), fn f -> %>
<label>
Login: <%= text_input f, :login %>
</label>
<label>
Password: <%= password_input f, :password %>
</label>
<label>
Name: <%= text_input f, :name %>
</label>
<label>
Surname: <%= text_input f, :name %>
</label>
<label>
Email: <%= email_input f, :name %>
</label>
<label>
Class: <%= text_input f, :name %>
</label>
<label>
Phone: <%= text_input f, :name %>
</label>
<%= submit "Submit" %>
<% end %>
</div>
Run Code Online (Sandbox Code Playgroud)
这是由财务主任提供的:
def index(conn, _params) …Run Code Online (Sandbox Code Playgroud) 是否有可能找到已采用某些行为的每个已加载模块?
我正在构建一个非常简单的聊天Bot,我想制作一些很酷的命令,但要实现这一点,我需要一种方法来实现多个命令,最好不要硬编码.
每个命令都是一个函数,它接受三个参数(message,author,chat_channel_ref)并返回true或false,无论它是否匹配并执行某些操作.
当我浏览Elixir教程时,如果能找到所有采用它们的模块,我会发现可能非常适合我的需求的行为.你以前有没有人这样做过?我还能做什么?我还想过"使用"(在使用中我将执行代码以将当前模块添加到代理所持有的列表中).