如何将选定值传递给vuejs函数?
v-model我想不会有帮助.
我需要在item: items | orderBy sortKey reverse
where reverse和sortKey是动态值之后设置过滤器的
值.
HTML
<select class="sort-filter" v-on="change: sortBy(???)">
<option value="title asc">Title (A-Z)</option>
<option value="title desc">Title (Z-A)</option>
<option value="price asc">Price (Min. - Max.)</option>
<option value="price desc">Price (Max. - Min.)</option>
</select>
Run Code Online (Sandbox Code Playgroud)
JS
methods: {
sortBy: function (sortKey) {
console.log(sortKey)
}
}
Run Code Online (Sandbox Code Playgroud) 使用本教程
http://railscasts.com/episodes/57-create-model-through-text-field
需要让它在我的应用程序中工作,在rails 3.0.7上工作正常,更新到3.1.3我现在收到此错误
uninitialized constant ActionView::CompiledTemplates::Category
Run Code Online (Sandbox Code Playgroud)
我会寻找更多时间的答案,但现在我的时间非常短.我已经调查了与此问题相关的谷歌搜索结果的大部分内容并没有什么好处.需要帮助.
形成
<%= f.collection_select :category_id, Category.find(:all), :id, :name, :prompt => "Select a Category" %>
or create one:
<%= f.text_field :new_category_name %>
Run Code Online (Sandbox Code Playgroud)
模型
class Tvstation < ActiveRecord::Base
belongs_to :category
attr_accessor :new_category_name
before_save :create_category_from_name
def create_category_from_name
create_category(:name => new_category_name) unless new_category_name.blank?
end
end
Run Code Online (Sandbox Code Playgroud) 的Gemfile
gem "wicked_pdf"
gem "wkhtmltopdf-binary"
Run Code Online (Sandbox Code Playgroud)
错误:
RuntimeError in CarsController#show
Failed to execute:
/usr/bin/wkhtmltopdf --print-media-type -q - -
Error: PDF could not be generated!
Rails.root: /u/apps/zeepauto/autozeep_update
Run Code Online (Sandbox Code Playgroud)
cars_controller
def show
@class_showcar = true
@class_admin = true
@car = Car.find(params[:id])
@search = Car.search(params[:search])
@cars_see_special = Car.where(:special => "1").order('rand()').limit(3)
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @car }
format.pdf do
render :pdf => "#{@car.carname.name}",
:print_media_type => true
end
end
end
Run Code Online (Sandbox Code Playgroud)
show.html.erb
<p class="show_links"><%= link_to url_for(request.params.merge(:format => :pdf)) do %>
<%= …Run Code Online (Sandbox Code Playgroud) 尝试使用jquery选择 vue,问题是这个插件隐藏了我应用的实际选择v-model,所以当我选择一个值时,vue不会将其识别为select change事件,并且模型值不会更新.
当我选择一些东西时,select的值实际上正在改变,我用console.log检查了这个值以查看所选的值.
http://jsfiddle.net/qfy6s9Lj/3/
我能做到vm.$data.city = $('.cs-select').val(),这似乎有效,但还有另一种选择吗?如果select的值被更改,为什么vue没有看到这个?
故事:
我在产品页面#/product/7和同一页面上我还有4个产品与正在查看的产品相似.所有这些产品都有链接到他们的页面:
router-link(:to="{ name: 'product', params: { id: product.id }}" v-text='product.title').
问题:
当我点击任何产品链接时,网址会发生变化但内容保持不变.所以,如果我打开#/product/7并点击#/product/8该网址只会改变.如果我从/product/:id页面导航并单击某个产品,它会将我带到正确的页面并显示正确的内容.
正如您在屏幕截图中看到的那样,当前产品ID为15,但内容是来自id 7的内容,如底部的url所示,而我正在购物车中的Sleek Silk Shirt产品上方悬停.任何想法如何解决这一问题?
我试图以某种方式显示line items了order在active_admin order show page,没有运气..
这里是模型之间的关系:
order.rb
class Order < ActiveRecord::Base
has_many :line_items, :dependent => :destroy
# ...
validates :name, :address, :email, :presence => true
validates :pay_type, :inclusion => PAYMENT_TYPES
end
Run Code Online (Sandbox Code Playgroud)
line_item.rb
class LineItem < ActiveRecord::Base
belongs_to :order
belongs_to :product
belongs_to :cart
def total_price
product.price * quantity
end
end
Run Code Online (Sandbox Code Playgroud)
active_admin order.rb
ActiveAdmin.register Order do
show do
attributes_table :name, :email, :address, :pay_type, :created_at, :updated_at
end
end
Run Code Online (Sandbox Code Playgroud)
active_admin line_item.rb
class LineItem < ActiveRecord::Base
belongs_to :order
belongs_to :product …Run Code Online (Sandbox Code Playgroud) 最近转移到Rails 4并得到我之前没有得到的错误.我正在尝试使用Capybara/Rspec测试我正在制作的表格.
当我单击表单上的按钮时,我得到的错误是:
Failure/Error: find(".submit.button").click
ActionController::UnknownFormat:
ActionController::UnknownFormat
# ./app/controllers/office_listings_controller.rb:32:in `create'
# ./spec/features/office_listings_spec.rb:78:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
它指向我的控制器,看起来像:
def create
selected_amenities = params[:amenities] || [] # empty list if no amenities checked
@office_listing = OfficeListing.new(params[:office_listing])
@office_listing.broker = current_broker
p current_broker
@office_listing.neighborhood = Neighborhood.find(params[:neighborhood_id])
p @office_listing.neighborhood
if @office_listing && @office_listing.save!
@path = city_neighborhood_office_listing_path(@office_listing, :city_id => @office_listing.neighborhood.city.id, :neighborhood_id => @office_listing.neighborhood.id)
create_amenities(@office_listing, selected_amenities)
respond_to do |format|
format.js
end
else
@failure = "Unable to create office :-("
respond_to do |format|
format.js
end
end …Run Code Online (Sandbox Code Playgroud) Course.rb
min_age: integer
max_age: integer
Run Code Online (Sandbox Code Playgroud)
学生年龄来自params[:age]- 例如15 岁,这意味着学生15岁,他寻找的课程将涵盖他的年龄:
我有课程:
id min_age max_age
------------------------
1 5 15
2 10 25
3 10 55
4 20 40
Run Code Online (Sandbox Code Playgroud)
题:
如何查找min_age和max_age涵盖年龄参数值的所有记录?如果学生说他15岁,他应该看到的课程是:
1,2和3因为这些是涵盖这个年龄的人.
更多,我需要在搜索模型中使用它来创建搜索记录,当有人搜索课程并且返回的结果是用户(提供这些课程的导师)时.
def find_courses
users = User.joins(:courses).where("courses.lesson ILIKE ?", "%#{lesson}%")
# failed attempt:
users = users.where('course.min_age >= :age or courses.max_age <= :age', age: age)
end
Run Code Online (Sandbox Code Playgroud)
感谢您的时间.
根据接受的答案:
Course.where('min_age <= :age AND max_age >= :age', age: 18)
Run Code Online (Sandbox Code Playgroud)
上面的sql将要求两个条件都为true才能显示记录:
id min_age max_age
------------------------
1 5 true + 15 false = false
2 10 …Run Code Online (Sandbox Code Playgroud) 简介:simple_form在应用程序中
使用时,添加到属性和错误的验证会正确显示在表单中的每个字段旁边。我还有2个自定义验证,可添加与模型属性无关的自定义错误消息。
问题:
在基本Rails表单中,错误显示在表单上方,并且还会显示来自自定义验证的错误。但是,如何使用显示自定义验证消息simple_form?
这是它应该如何工作:我登录到管理面板,转到汽车/新的,填写字段,按创建,我应该在我的列表中有一辆新车.www.autozeep.com
问题是,在按下"创建"按钮创建新车之前,它可以正常运行,服务器日志显示如下:
NameError (uncaught throw `warden'):
app/controllers/application_controller.rb:9:in `login_required'
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
Run Code Online (Sandbox Code Playgroud)
在开发模式下,这工作正常,在生产模式的服务器上它不是,它是相同的代码,没有任何改变.更多服务器日志:http://pastie.org/3028350
application_controller
class ApplicationController < ActionController::Base
protect_from_forgery
# filter
def login_required
return true if authenticated?
warden.authenticate!
end
Run Code Online (Sandbox Code Playgroud)
users_controller:http://pastie.org/3028586
我可以编辑汽车,它工作正常,所以来自cars_controller的更新和编辑功能都可以,我检查了新的并从cars_controller创建函数,但我无法解决任何会让我知道发生了什么的事情.Cars_controller:http://pastie.org/3028452
请帮忙,我已经运行了这个应用程序,等待这个问题的客户端只能解决.非常感谢你们.
编辑
NameError in CarsController#create
uncaught throw `warden'
Rails.root: /u/apps/zeepauto/releases/20111123173432
Application Trace | Framework Trace | Full Trace
app/controllers/application_controller.rb:9:in `login_required'
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
ENV DUMP
...
....
rack.url_scheme: "http"
rack.version: [1, 0]
warden: Warden::Proxy:-621456458 @config={:default_strategies=>{:_all=>[:database]}, :failure_app=>UsersController, :default_scope=>:default, :scope_defaults=>{}, :intercept_401=>true}
warden.options: {:attempted_path=>"/cars", :action=>"unauthenticated"}
Run Code Online (Sandbox Code Playgroud)
我只有在添加新车时才会出现此错误,我可以编辑汽车,新闻,联系人.汽车以外的一切. …
vue.js ×3
activeadmin ×1
activerecord ×1
postgresql ×1
rspec ×1
ruby ×1
simple-form ×1
vue-router ×1
warden ×1
wicked-pdf ×1