我通过POST发送表单数据,但没有设置相应的POST变量,也没有.
此外,当我将POST数据存储到本地PHP变量时,我似乎无法使用这些变量.(一旦我解决了第一个问题,我有一种感觉,我也可以使用变量.)
第二页输出的错误消息(见下文)是:
Notice: Undefined variable: postUsername in (...somepath)\scripts\create-member.php on line 10
Run Code Online (Sandbox Code Playgroud)
(表格页面):
<form action="scripts/create-member.php" method="POST">
<input type="text" name"username" value="" placeholder="User Name"> <br />
<input type="password" name"password" value="" placeholder="Password"> <br />
<input type="password" name"passwordConfirm" value="" placeholder="Confirm Password"> <br />
<!-- ?type email or type text -->
<input type="email" name"email" value="" placeholder="Email" autofocus> <br />
<input type="submit" name="submitRegistration" value="Register!">
</form>
Run Code Online (Sandbox Code Playgroud)
(第二页)scripts\create-member.php:
<?php
//!proper way to declare variables obtained from POST.
// Data from form "register.php"
if ( isset($_POST['username']) ) {
$postUsername …Run Code Online (Sandbox Code Playgroud) 通过关系,我有一个标准的has_many.人类通过连接表交互有许多兽人.互动只是一个表格和模型; 没有控制器或视图.
使用Rails 4中的simpleform gem,我想从人体页面创建一个表单,以便从所有兽人的池中选择多个兽人.提交后,我希望它在交互表中创建/更新尽可能多的记录,每个记录都包含人工ID,并且选择了多个orc ID.:
AKA列表符号
human_id并且orc_id从该列表中选择兽人.(human_id在这些记录中将是相同的,因为它从给定的人类表单页面开始)我将尽可能多地编写整个故事的代码.请随时要求澄清,并解决任何错误,以实现这一点.
表
humans
integer "id"
interactions
integer "human_id"
integer "orc_id"
index ["human_id", "orc_id"]
# This is the primary key. no normal id.
# Is it better to have a primary id for this join table, or does it not matter?
orcs
integer "id"
Run Code Online (Sandbox Code Playgroud)
楷模
/models/human.rb
class Human < ActiveRecord::Base
has_many :interaction
has_many :orcs, through: :interactions
accepts_nested_attributes_for :interactions
end
Run Code Online (Sandbox Code Playgroud)
/models/interaction.rb
# Purely a join model and …Run Code Online (Sandbox Code Playgroud) 有人可以解释以下命令之间的区别吗?
rake assets:precompile
bin/rake assets:precompile
RAILS_ENV=production rake assets:precompile
RAILS_ENV=production bin/rake assets:precompile
当我进入角色控制器,显示动作时,所有正常的参数[:id]都是如何根据REST进行的.
在节目视图中,我渲染了一个部分.在那个部分,我有一个链接到vote_socionics行动.此操作在socionics_votes模块下定义,该模块由字符控制器包含.(我有这样设置,因为我有其他控制器,也包括这个模块).
我的问题是,当我点击这个链接,它进入文件中的set_votable私有方法时socionics_votes_module.rb,params[:id]它不再存在.使用撬,我发现它实际上变成了params[:character_id]
问题:
1)为什么会发生这种情况(是因为它进入"不同"的控制器,即使它是一个模块?)
2)我该如何解决这个问题?我认为将它设为params [:id]会更优雅,而不必为if-else设置两个密钥.
characters_controller.rb
class CharactersController < ApplicationController
include SocionicsVotesModule
def show
@character = Character.find(params[:id])
end
Run Code Online (Sandbox Code Playgroud)
字符/ show.html.haml
= render partial: 'votes/vote_socionics',
locals: { votable: @votable, votable_name: @votable_name, socionics: @socionics }
Run Code Online (Sandbox Code Playgroud)
_vote_socionics.html.haml
= link_to content_tag(:div,"a"), send("#{votable_name}_vote_socionics_path", votable, vote_type: "#{s.type_two_im_raw}"),
id: "vote-#{s.type_two_im_raw}",
class: "#{current_user.voted_on?(votable) ? 'voted' : 'not-voted'}",
method: :post,
data: { id: "#{s.type_two_im_raw}" }
Run Code Online (Sandbox Code Playgroud)
socionics_votes_module.rb
module SocionicsVotesController
extend ActiveSupport::Concern
included do
before_action :set_votable
end
private …Run Code Online (Sandbox Code Playgroud) 我的文件结构是这样的
app
assets
bookshelf
assets
my_image.jpg
images
standard_image.png
Run Code Online (Sandbox Code Playgroud)
在我的css.scss文件中,这两个都在开发中,但它们在生产中不起作用.
#some_div {
background: url("standard_image.png")
}
#some_div {
background: url("assets/my_image.jpg")
}
Run Code Online (Sandbox Code Playgroud)
我已经做了RAILS_ENV=production rake assets:clean assets:precompile.我删除了我的tmp/cache.
我觉得这可能是配置问题.我错过了什么?
我知道图像在服务器上.我得到了消化的文件名,并将其放入带有生产根地址的URL中.
当我尝试使用时
background: asset-url("assets/my_image.jpg", image)
Run Code Online (Sandbox Code Playgroud)
我明白了
Sprockets :: Rails :: Helper :: AssetFilteredError at books
资产过滤掉,将不送达:添加
Rails.application.config.assets.precompile += %w( assets/bookshelf_skin02_top_bg.jpg )到config/initializers/assets.rb并重新启动服务器
显然,我不想在配置中添加每个资产文件.
match '*path' => redirect('/'), via: :all if Rails.env.production? 很好地处理事情,但它不能正确地捕捉这样的情况
/root.com/articles/293 其中 293 是数据库中不存在的文章 ID。
在这种情况下,它仍然重定向到默认的 404 页面,这在 heroku 上是丑陋的“出现问题”页面。
如何利用“有效的 url,但无效的资源 ID” url 来控制其重定向到我想要的位置?
当你使用时{{}},苗条看第一个{并认为它是一个属性.
如何禁用{苗条的关键角色.使用{{ }}将被解释为角度,而不是苗条的属性?
(PS我正在使用slim-railsgem,所以解决方案可能特定于rails,但谁知道呢?)
如果查询参数值是默认值,则Ember不会在URL中显示查询参数。但我想展示一下。是否可以将这种行为更改为显示而不是隐藏?
App.IndexController = Ember.ArrayController.extend({
queryParams: ['type'],
type: "horror" // the default value, won't appear in URL or params
})
Run Code Online (Sandbox Code Playgroud) 我一直在
错误:SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法中有错误; 查看与您的MySQL服务器版本对应的手册,以便在附近使用正确的语法
请帮忙!=]我已经检查过phpmyadmin中的这个文字查询是否有效.
SELECT *
FROM `wp_customgravityall`
WHERE (`time` >= '2015-09-01 00:00:00' AND `time` <= '2015-09-13 23:59:59')
ORDER BY `wp_customgravityall`.`time` DESC
Run Code Online (Sandbox Code Playgroud)
但我的下面的代码不起作用.
<?php
$servername = "http://www.myhomepagenamethingy.com/";
$username = DB_USER;
$password = DB_PASSWORD;
$dbname = DB_NAME;
$table_name = 'wp_' . 'customgravityall';
$from_date = isset( $_GET['from_date'] ) ? $_GET['from_date'] . " " . "00:00:00" : '';
$to_date = isset( $_GET['to_date'] ) ? $_GET['from_date'] . " " . "23:59:59" : '';
try {
$conn = new PDO('mysql:$servername;dbname=$dbname', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); …Run Code Online (Sandbox Code Playgroud) 为mac指定"命令"按钮的关键字是什么?
我希望能够按"command + t"打开一个新选项卡.
我在keybindings文件中输入什么内容?
这不起作用.[{"keys":["command + t"],"command":"new_tab"},]
从设计的角度来看,要求将变量传递给部分以便从部分中访问它们有哪些优点或必要性?
简单地能够在父/祖父母视图已经设置的部分中使用变量会有什么问题或缺点?
php ×2
angularjs ×1
assets ×1
css ×1
database ×1
ember.js ×1
forms ×1
input ×1
key-bindings ×1
nested-forms ×1
path ×1
pdo ×1
precompile ×1
redirect ×1
routes ×1
sass ×1
set ×1
simple-form ×1
slim-lang ×1
sublimetext ×1
variables ×1
wordpress ×1