我试图传递一个变量来渲染像这样:
def monitor
@peripheries = Periphery.where('periphery_type_name=?','monitor')
render 'index', type: 'Monitor'
end
Run Code Online (Sandbox Code Playgroud)
这里我想在索引视图中使用'type'变量,它看起来像这样:
<%= render 'some_partial', periphery_type: type %>
Run Code Online (Sandbox Code Playgroud)
这也是一些东西.但我想使用那个'type'变量
如何将ISO8601时间格式的字符串转换为python3 datetime.这是我的时间:
2017-03-03T11:30:00+04:00Run Code Online (Sandbox Code Playgroud)
我尝试的方式:
datetime.strptime(appointment['datetime'], '%Y-%m-%dT%H:%M:%S%z')Run Code Online (Sandbox Code Playgroud)
这里的问题是,我不知道如何在.strptime方法的格式参数中表示+4:00时区.
我想根据选择值生成一些复选框。所以我有选择标签:
<%= f.collection_select :type, RequestType.order(:typeName), :id, :typeName,
{include_blank:true }, {:class => "types"} %>Run Code Online (Sandbox Code Playgroud)
当 select 的值更改时,我想生成一些复选框,为此我有 div:
<div id="sub_types"> </div>Run Code Online (Sandbox Code Playgroud)
def show_sub_types
@rtype = params[:id];
@stypes = RequestSubType.where("request_type_id=?", @rtype).all
respond_to do |format|
format.js
format.html
end
endRun Code Online (Sandbox Code Playgroud)
$("#sub_types").html("");
$("#sub_types").append("<%= j render 'show_sub_types', stypes: @stypes %>");Run Code Online (Sandbox Code Playgroud)
<% stypes.each do |type| %>
<%= check_box_tag "subtype", type.id %>
<%= type.subTypeName %>
<br>
<% end %>Run Code Online (Sandbox Code Playgroud)
在我的部分我做这样的事情。此代码生成我的复选框。他们看起来像这样:
<input type="checkbox" name="subtype" id="subtype" value="1">Run Code Online (Sandbox Code Playgroud)
但现在我不知道如何用我的表单提交这些复选框值。我想在 db 中存储多个复选框值作为数组。
var code ='';
alert(branch+"t"); // resutl: 123t
for(var i=0;i<endVar;i++){
code = code+branch;
}
alert(code);// result: 123 123 123 etc..Run Code Online (Sandbox Code Playgroud)
假设我有几个表并想要执行联接查询:
schedule_calendars = ScheduleCalendar.query\
.join(Schedule)\
.join(ClinicBranchHasDoctor)\
.filter_by(clinic_branch_id=clinic_id, doctor_has_specialty_id=doctor_speciality_id).all()
Run Code Online (Sandbox Code Playgroud)
问题是我的结果将仅包含ScheduleCalendar类的属性。如何查询,以便我的结果将包含所有联接表的属性。
时间表:
id = Column(db.Integer, primary_key=True)
added_date = Column(db.DateTime(timezone=True), default=get_current_time, nullable=False)
start_date = Column(db.Date, nullable=False)
name = Column(db.String(128), nullable=False)
is_valid = Column(db.Boolean, default=IS_VALID, nullable=False)
slot_size = Column(db.Integer, default=30)
Run Code Online (Sandbox Code Playgroud)
ScheduleCalendar:
schedule_id = Column(db.Integer, db.ForeignKey("schedules.id"), nullable=False)
Run Code Online (Sandbox Code Playgroud)
ClientBranchHasDoctor:
schedule_id = Column(db.Integer, db.ForeignKey("schedules.id"), nullable=False)
Run Code Online (Sandbox Code Playgroud)
我在这里跳过了一些属性。我认为最重要的是我的表具有适当的约束,否则联接将失败。
我对流星很陌生。我正在做简单的应用程序。这是我遇到的问题:
Template.newFeedForm.events({
'submit #new-feed-form'(event) {
event.preventDefault();
const target = event.target;
const text = target.text;
Meteor.call('feeds.insert', text);
target.text.value = '';
}
});Run Code Online (Sandbox Code Playgroud)
所以我有 newFeedForm 模板,在我的 feeds.js 中我有
Meteor.methods({
'feeds.insert'(text){
check(text, String);
//check(hashtag, String);
// Make sure the user is logged in before inserting a task
if (! this.userId) {
throw new Meteor.Error('not-authorized');
}
console.log(this.userId);
// Feeds.insert({
// text: text,
// owner: this.userId,
// username: Meteor.users.findOne(this.userId).username,
// createdAt: new Date()
// });
}
});Run Code Online (Sandbox Code Playgroud)
我在这里注释掉了 Feeds.insert ,认为它会导致问题。看来是有些不一样了。每当执行 Meteor.call 时,我都会得到以下信息:
Uncaught RangeError: Maximum …Run Code Online (Sandbox Code Playgroud)我正在使用PostgreSQL 9.6.我有一个查询像这样:
SELECT anon_1.id AS anon_1_id, anon_1.is_valid AS anon_1_is_valid, anon_1.first_name AS anon_1_first_name, anon_1.last_name AS anon_1_last_name,
anon_1.patronymic_name AS anon_1_patronymic_name,
anon_1.experience AS anon_1_experience, anon_1.user_id AS anon_1_user_id, anon_1.rating_points as rating_points
FROM (SELECT DISTINCT ON (doctors.id) doctors.id AS id, doctors.created_at AS created_at, doctors.updated_at AS updated_at, doctors.is_valid AS is_valid, doctors.pretty_url AS pretty_url, doctors.first_name AS first_name, doctors.last_name AS last_name, doctors.patronymic_name AS patronymic_name, doctors.phone AS phone, doctors.birthday AS birthday, doctors.avatar AS avatar, doctors.experience AS experience, doctors.science_degree AS science_degree, doctors.sex_id AS sex_id, doctors.yclients_staff_id AS yclients_staff_id, doctors.user_id AS user_id, …Run Code Online (Sandbox Code Playgroud) 我有两个选择,第二个根据第一个的值而改变.我使用CoffeScript.
<%= f.collection_select :type, RequestType.order(:typeName), :id, :typeName,
{include_blank:true }, {:class => "types"} %>
<%= f.grouped_collection_select :subtype, RequestType.order(:typeName),
:RequestSubTypes, :typeName, :request_type_id, :subTypeName,
{include_blank:true},
{:class => "subTypes" } %>Run Code Online (Sandbox Code Playgroud)
jQuery ->
subTypes = $(".subTypes").html()
$(".subTypes").parent().hide()
$(".types").change ->
type = $(".types :selected").text()
options = $(subTypes).filter("optgroup[label='#{type}']").html()
if options
$(".subTypes").html(options)
$(".subTypes").parent().show()
else
$(".subTypes").empty()
$(".subTypes").parent().hide()Run Code Online (Sandbox Code Playgroud)
<%= link_to "link", new_request_path %>Run Code Online (Sandbox Code Playgroud)
我正在进行复杂的搜索,为此我有特殊的模型:
create_table "cmdb_searches", force: :cascade do |t|
t.string "client"
t.string "in"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Run Code Online (Sandbox Code Playgroud)
和evms_controller中的方法搜索:
def search
@cisearch = CmdbSearch.new(search_params)
@evms = Evm.order('id DESC')
@evms = @evms.where('client_name=?',@cisearch.client) if #cisearch.client.present?
@evms = @evms.where('in=?',@cisearch.in) if @cisearch.in.present?
respond_to do |format|
format.js
end
end
Run Code Online (Sandbox Code Playgroud)
并且我的js文件用响应填充了适当的div.如果我将表格留空或仅填写:客户字段,但是如果我填写:它在字段中它将返回错误:
SQLite3::SQLException: near "in": syntax error: SELECT "evms".* FROM "evms" WHERE (in='234543') ORDER BY id DESC
Run Code Online (Sandbox Code Playgroud) <%= f.select :id, options_from_collection_for_select(
@rtypes, "id", "typeName"),
{include_blank: true },
:onchange => ShowSubTypes() %> Run Code Online (Sandbox Code Playgroud)
这里我有 select 的选项,我想要的是将 id 作为参数传递给ShowSubTypes()函数。我的@rtypes变量返回一个数组,因此我不能只传递@rtypes.id.
我有带墨盒名称的墨盒模型:
t.string "cartridge_name", null: false
Run Code Online (Sandbox Code Playgroud)
我对它执行查询:
@cartridge = Cartridge.where('cartridge_name=?', "#{value[:cartridge_id]}")
Run Code Online (Sandbox Code Playgroud)
它返回一个对象:
<ActiveRecord::Relation [#<Cartridge id: 1, cartridge_name: "HP laserjet 3000", note: "", created_at: "2015-04-14 08:05:37", updated_at: "2015-04-14 08:05:37">]>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试访问@ cartridge.id或@ cartridge.cartridge_name时,它会返回错误:
NoMethodError: undefined method `cartridge_name' for #<Cartridge::ActiveRecord_Relation:0x007fbd77bf38f8>
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会这样.什么可能导致错误?
我有一个cartridge和dosing_edge模型,他们分别有关系has_many和belongs_to.通过这样做我可以打电话:
@cartridge.dosing_edges
Run Code Online (Sandbox Code Playgroud)
检索属于盒式磁带的所有dosing_edges.这样可行,但墨盒模型也有一个dosing_edges属性.如何区分方法和属性.
我的意思是,如果我想访问@cartridge.dosing_edges不调用方法.dosing_edges来检索所有dosing_edges.
或者我应该将我的dosing_edges属性重命名为不同.
javascript ×4
jquery ×2
python ×2
checkbox ×1
coffeescript ×1
date ×1
flask ×1
html ×1
limit ×1
meteor ×1
postgresql ×1
python-3.x ×1
ruby ×1
sql ×1
sqlalchemy ×1