我正在尝试使用我的javascript来渲染关于元素点击的新视图,使用此代码;
package it.jack.fdd.dao.impl;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import it.jack.fdd.dao.interfaces.BankAccountDao;
import it.jack.fdd.domain.BankAccount;
import it.jack.fdd.domain.Staff;
import it.jack.fdd.domain.User;
import it.jack.fdd.util.HibernateUtilLezione;
public class BankAccountDaoImpl extends BaseDaoImpl<BankAccount> implements BankAccountDao{
public List<BankAccount> getBAByUserId(int id) {
try{
Session session = HibernateUtilLezione.openSession();
Transaction tx = session.beginTransaction();
@SuppressWarnings("unchecked")
List<BankAccount> accounts = session.createQuery("from BankAccount b "
+ "where b.user= "+id).list();
tx.commit();
session.close();
return accounts;
}
catch(HibernateException e){
e.printStackTrace();
return null;
}
}
}
我收到以下错误:
$(document).ready(function() {
$('.link-panel').click( function() {
window.location.replace('/quotes/'+gon.gon_quote_id);
});
});
quote_controller.rb:
Couldn't find Quote with 'id'=undefined [WHERE "quotes"."user_id" = $1]
端
我认为这必须是我给 def show
@quote = current_user.quotes.find(params[:id])
gon.gon_quote_id = @quote.id
end
def index
@quotes = current_user.quotes.all
# how to pass the individual quote object's id to gon here
方法提供url参数的方式,你能帮助我解决我做错的事吗?
(replace
设置正常,因为警报测试证明。)
由于
答案 0 :(得分:0)
您应该使用网址中的id
参数:
window.location.replace('/quotes/?id=' + gon.gon_quote_id);
答案 1 :(得分:0)
脚本不知道它是从rails访问变量的,你必须这样做:
$(document).ready(function() {
$('.link-panel').click( function() {
window.location.replace('/quotes/'+<%= gon.gon_quote_id %>);
});
});