我刚刚升级到Rails 5并且一切都很顺利但是没有明显的原因,一个被调用的方法skip_before_action不允许rspec运行此消息
在process_action回调之前:尚未定义redirect_heroku_user(ArgumentError)
这是非常奇怪的,因为它在rails 4上运行得很好.这是我的代码:
# application_controller.rb
def redirect_heroku_user
redirect_to root_path if heroku_user?
end
# some_controller.rb
skip_before_action :redirect_heroku_user, only: :edit
Run Code Online (Sandbox Code Playgroud) 我需要在输入中放置图标以创建新用户.对于那些了解前端代码的人来说,这可能是一项非常容易的任务.但是我没有.这是线框,然后我显示我的代码.
如你看到的.输入左侧有图标.现在我在我的目录中有SVG,准备好了,我只需要知道如何将它们放在输入中.这是表单的代码
<label clas="name-label">
<%= f.text_field :name, placeholder: "Name", class: "form-labels" %>
</label>
<label class="email-label">
<%= f.text_field :email, placeholder: "Email", class: "form-labels" %>
</label>
Run Code Online (Sandbox Code Playgroud)
所以我有一个占位符,其中包含一个当前只打印该字符串的字符串.我需要把图标放在我认为的范围内吗?这是我用于图标的CSS.
.icon-email {
background-image: image-url('email-field.svg');
}
.icon-name {
background-image: image-url('name-field.svg');
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将这些类放在占位符中?
我正在尝试在屏幕上显示一个表单.但是当我尝试启动服务器时,我一直收到此错误.locations_controller.ex ==
** (CompileError) web/controllers/locations_controller.ex:5: Locations.__struct__/1 is undefined, cannot expand struct Locations.顺便说一下,我是elixir的新手,所以我可能做了一些非常明显错误的事情.
这是我的代码:
def new(conn, _params) do
changeset = Locations.changeset(%Locations{})
render conn, "new.html", changeset: changeset
end
def create(conn, %{"locations" => %{ "start" => start, "end" => finish }}) do
changeset = %AwesomeLunch.Locations{start: start, end: finish}
Repo.insert(changeset)
redirect conn, to: locations_path(conn, :index)
end
Run Code Online (Sandbox Code Playgroud)
<h1>Hey There</h1>
<%= form_for @changeset, locations_path(@conn, :create), fn f -> %>
<label>
Start: <%= text_input f, :start %>
</label>
<label>
End: <%= text_input f, …Run Code Online (Sandbox Code Playgroud) 我想删除模式中的表.我在第一次启动项目时创建了数据库,并希望删除表.这样做的最佳方式是什么?
我试过rails g migration drop table :installs但是只是创建了一个空迁移?
架构:
create_table "installs", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "installs", ["email"], name: "index_installs_on_email", unique: true
add_index "installs", ["reset_password_token"], name: "index_installs_on_reset_password_token", unique: true
Run Code Online (Sandbox Code Playgroud) 我在尝试创建数据库时遇到错误.我安装了postgres,我已经成功完成了一些测试项目.而且,我没有看到这个错误.任何帮助都会很棒:
错误:
~/Desktop/elixir/restore $ mix ecto.create
** (Mix) The database for Restore.Repo couldn't be created: tcp connect: connection refused - :econnrefused
21:52:23.978 [error] GenServer #PID<0.150.0> terminating
** (Postgrex.Error) tcp connect: connection refused - :econnrefused
(db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
(connection) lib/connection.ex:623: Connection.enter_connect/5
(stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行一个函数,该函数需要从挂载方法中获取的一些数据。现在我尝试使用computed来创建函数,但不幸的是,对于这种情况,之前计算过的运行,mounted所以我没有函数所需的数据。这是我正在使用的内容:
computed: {
league_id () {
return parseInt(this.$route.params.id)
},
current_user_has_team: function() {
debugger;
}
},
mounted () {
const params = {};
axios.get('/api/v1/leagues/' +this.$route.params.id, {
params,
headers: {
Authorization: "Bearer "+localStorage.getItem('token')
}
}).then(response => {
debugger;
this.league = response.data.league
this.current_user_teams = response.data.league
}).catch(error => {
this.$router.push('/not_found')
this.$store.commit("FLASH_MESSAGE", {
message: "League not found",
show: true,
styleClass: "error",
timeOut: 4000
})
})
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我debugger在计算函数中调用了current_user_has_team函数。但是我需要从 axios 调用中返回的数据。现在我在调试器中没有数据。我应该使用什么回调,以便我可以利用从网络请求返回的数据?谢谢你!
我知道before_filter不推荐使用rails.我不是在打电话,但出于某种原因,我收到的消息是说我是.before_filter is deprecated and will be removed in Rails 5.1. Use before_action instead. (called from <top (required)> at /Users/intern/Desktop/Work/app/config/environment.rb:5)
在environment.rb第5行的那个文件中,我没有在过滤器之前调用但是这行Rails.application.initialize!
为什么在没有被调用时使用过滤器?任何帮助都会很棒!谢谢.
我看到很多使用 Vuetify 进行客户端验证的文档,但发现很难找到 vuetify 和 vue 的服务器端验证消息的文档。
我有这个组件:
<template>
<v-container>
<v-layout row>
<v-flex xs12 sm6 offset-sm3>
<v-card>
<v-card-text>
<v-container>
<h3>Register Now</h3>
<form v-on:submit.prevent="onSubmit">
<v-layout row>
<v-flex xs12>
<v-text-field
name="email"
label="Email"
type="email"
ref="user_email"
id="email">
</v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12>
<v-text-field
name="password"
label="Password"
type="password"
ref="user_password"
id="password">
</v-text-field>
</v-flex>
</v-layout>
<v-layout row>
<v-flex xs12>
<v-btn type="submit">Sign Up</v-btn>
</v-flex>
</v-layout>
</form>
</v-container>
</v-card-text>
</v-card>
</v-flex>
</v-layout>
</v-container>
</template>
<script>
import axios from 'axios'
import router from 'vue-router'
export default {
data() …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试我是否正确地转换了从第三方 api 返回的数据。我在使用 Mox 时遇到了一些麻烦,因为我需要在数据转换期间点击两个单独的端点。让我通过发布代码更清楚地解释:
test "players/0 return all active players" do
Statcasters.SportRadarNbaApi.ClientMock
|> expect(:league_hierarchy, fn ->
{:ok, league_hierarchy_map()}
end)
Statcasters.SportRadarNbaApi.ClientMock
|> expect(:team_profile, fn _ ->
{:ok, team_profile_map()}
end)
assert Statcasters.Sports.Nba.get_players() == ["Kevon Looney", "Patrick McCaw"]
end
Run Code Online (Sandbox Code Playgroud)
def get_players do
with {:ok, hierarchy} <- @sport_radar_nba_api.league_hierarchy,
team_ids <- get_team_ids(hierarchy),
players <- get_team_players(team_ids)
do
IO.inspect players
end
end
defp get_team_players(team_ids) do
for team_id <- team_ids do
{:ok, team} = @sport_radar_nba_api.team_profile(team_id)
end
end
Run Code Online (Sandbox Code Playgroud)
忽略编写的代码实际上不会通过测试的事实。这是我试图弄清楚的测试失败。
第二个 api 调用team_profile在测试中被调用两次,因为我遍历了两次,team_ids …
我有一个模型,用于制作看起来非常简单的加号.但是,我的css技能不是很棒.制作圆圈并不是什么大不了的事情,但在里面加上一个加号我似乎无法弄明白.这就是我想要做的.
这是我现在拥有的
到目前为止,这是我的代码:
<div class=circle></div>
Run Code Online (Sandbox Code Playgroud)
.circle {
border-radius: 50%;
width: 200px;
height: 200px;
background-color: rgb(44,108,128)
}
Run Code Online (Sandbox Code Playgroud)
所以非常基本的东西,但如果有人知道如何添加加号,你会让我的夜晚更好!谢谢您的帮助!
elixir ×3
ruby ×3
css ×2
html ×2
vue.js ×2
ecto ×1
javascript ×1
mox ×1
postgresql ×1
rspec ×1
struct ×1
svg ×1
vuetify.js ×1