在rails应用程序中,我有一个创建产品页面,其中包含一个嵌套的照片表单.有验证确保总有照片存在.但是,当我尝试在没有照片的情况下提交表单时,产品表单会在没有照片输入字段的情况下重新呈现.
新产品页面haml
= form_for @product,:url => products_path, :html => { :multipart => true } do |f|
- if @product.errors.any?
.error_messages
%h2 Form is invalid
%ul
- for message in @product.errors.full_messages
%li
= message
- if @photo.errors.any?
.error_messages
%h2 Image is invalid
%ul
- for message in @photo.errors.full_messages
%li
= message
%p
= f.label :description
= f.text_field :description
%p
= f.fields_for :photos do |fp|
=fp.file_field :image
%br
%p.button
= f.submit
Run Code Online (Sandbox Code Playgroud)
产品控制器
class ProductsController < ApplicationController
def new …
Run Code Online (Sandbox Code Playgroud) 简单问题在这里.我想在ajax请求中发送两个字符串作为数据.问题在于这个ajax请求它只发送第二个数据而不是第一个.我如何在一个ajax请求中发送这两个?
$.ajax({ url: '#{add_cards_path}',
type: 'POST',
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', '#{form_authenticity_token}')},
dataType: "json",
data: 'credit_uri=' + response.data.uri,
data: 'address=' + $('.address').val(),
success: function(response) {
window.location.assign(location.protocol + '//' + location.host);
}
});
Run Code Online (Sandbox Code Playgroud)
我想发送"credit_uri"和"地址".怎么样?
我视图中的Ruby代码在heroku上崩溃了我的rails应用程序.同时它也在开发中.我正在使用HAML.
= @sold
- @sold.each do |x|
%p lorem
Run Code Online (Sandbox Code Playgroud)
无论@sold是否等于nil还是有值,它都会在第二行 中断- @sold.each do |x|
.你们有什么线索的原因吗?
控制器:
def activity
@user = current_user
@selling = @user.products.where( "quantity != ?", 0 )
@sold = @user.products.where( "quantity == ?", 0 )
end
Run Code Online (Sandbox Code Playgroud)
编辑: Heroku日志说
"HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
2013-10-21T03:21:40.646768+00:00 app[web.1]: 21: %p one
2013-10-21T03:21:40.646570+00:00 app[web.1]: 20: - @sold.each do |x|
2013-10-21T03:21:40.646570+00:00 app[web.1]: 17: %button Status
2013-10-21T03:21:40.646570+00:00 app[web.1]: 18: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用它gem "bitly"
来缩短我的rails应用程序中的链接.但它给了我一个错误INVALID_URI - '500'
def show
@product = Product.find(params[:id])
bitly = Bitly.new('my-user-name','my-api-key')
page_url = bitly.shorten(request.original_url)
@url = page_url.short_url
end
Run Code Online (Sandbox Code Playgroud)
request.original_url = http://localhost:3000/products/219
这有效: bitly.shorten("http://www.google.com")
但这不是: bitly.shorten("http://localhost:3000/products/219")
有什么线索的原因?
我在JS中有这行代码用于处理付款,但我不确定它在做什么,因为我以前从未见过这种语法糖.
var fund = response.card != null ? response.card[0] : response.bank_acct[0];
Run Code Online (Sandbox Code Playgroud)