ruby-on-rails-3

Javascript not loading due to net::ERR_CONTENT_LENGTH_MISMATCH

岁酱吖の 提交于 2020-01-10 17:20:22
问题 I've got an app that runs fine locally, but barfs in production. (Classic problem, right?) In production, the JS isn't firing correctly. When I open up the browser console, I see this error: net::ERR_CONTENT_LENGTH_MISMATCH When I look in the network tab of Developer Tools, is shows that it failed on a GET request for text/html. It's a cryptic error. I've only found two other SO posts that even mention is and they're unsolved. (For the interested: first post and second post) Any idea (1) what

Rails 3 & HTML 5 Microdata

跟風遠走 提交于 2020-01-10 15:36:49
问题 In Rails, is it possible to create a HTML 5 valueless attribute using any of the ActionView Helpers? I'm trying to create the HTML 5 itemprop microdata for google's BreadCrumbs. Here's the output I'd like to generate: <div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"></div> But you can see that the itemscope attribute value has no value. Ideally, I'd like to do something like this in Rails... content_tag(:div, "somecontent", :itemscope => nil, :item_type => "http://data

content_for vs yield in partials

好久不见. 提交于 2020-01-10 14:16:19
问题 In rails 3.0 with HAML (3.1.4) I have some template-like partial , like _template.html.haml: .panel.top = yield :panel_top .content = yield some another partial which will be displayed using prev template (all this stuff is rendered using AJAX, but this doesn't matter) - content_for :panel_top do .title.left = title content text and this worked like a charm in Rails 3.0 But, after upgrade to 3.2 this fails! Yiels just yields "content text", so I have "content text" twice and no title at all

Why I can not call super in define_method with overloading method?

China☆狼群 提交于 2020-01-10 14:12:40
问题 When I run code below it raise error: implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. (RuntimeError). I am not sure what is the problem. class Result def total(*scores) percentage_calculation(*scores) end private def percentage_calculation(*scores) puts "Calculation for #{scores.inspect}" scores.inject {|sum, n| sum + n } * (100.0/80.0) end end def mem_result(obj, method) anon = class << obj; self; end anon.class

Why I can not call super in define_method with overloading method?

穿精又带淫゛_ 提交于 2020-01-10 14:11:55
问题 When I run code below it raise error: implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. (RuntimeError). I am not sure what is the problem. class Result def total(*scores) percentage_calculation(*scores) end private def percentage_calculation(*scores) puts "Calculation for #{scores.inspect}" scores.inject {|sum, n| sum + n } * (100.0/80.0) end end def mem_result(obj, method) anon = class << obj; self; end anon.class

How to customize to_json response in Rails 3

倖福魔咒の 提交于 2020-01-10 12:54:31
问题 I am using respond_with and everything is hooked up right to get data correctly. I want to customize the returned json , xml and foobar formats in a DRY way, but I cannot figure out how to do so using the limited :only and :include . These are great when the data is simple, but with complex finds, they fall short of what I want. Lets say I have a post which has_many images def show @post = Post.find params[:id] respond_with(@post) end I want to include the images with the response so I could

How to save dates in local timezone to db with rails3?

做~自己de王妃 提交于 2020-01-10 10:42:30
问题 I have Rails3 application with model user and field expires_at created like this: t.column :expires_at, :timestamp In my database (postgresql) it has type: timestamp without timezone The problem is when I call: @user.expires_at = Time.now @user.save it is saved into database with UTC timezone (my local time is UTC + 1:00, Warsaw) but I don't want that. I just want to have time with my local timezone saved into the database (2011-03-30 01:29:01.766709, not 2011-03-29 23:29:01.766709) Can I

How to save dates in local timezone to db with rails3?

烂漫一生 提交于 2020-01-10 10:42:27
问题 I have Rails3 application with model user and field expires_at created like this: t.column :expires_at, :timestamp In my database (postgresql) it has type: timestamp without timezone The problem is when I call: @user.expires_at = Time.now @user.save it is saved into database with UTC timezone (my local time is UTC + 1:00, Warsaw) but I don't want that. I just want to have time with my local timezone saved into the database (2011-03-30 01:29:01.766709, not 2011-03-29 23:29:01.766709) Can I

Check username availability using jquery and Ajax in rails

亡梦爱人 提交于 2020-01-10 09:22:12
问题 I am using rails with jquery and ajax to check the availability of username. I am using the following plugin for jquery validation purpose. https://github.com/posabsolute/jQuery-Validation-Engine In my controller i am using the following method to check the username availability. def check_name name = params[:name] if name.strip == "" render :json => { :available => false } return end user = User.find(:first, :conditions => [ "name = ?", name]) if user render :json => ["name", false , "This

Check username availability using jquery and Ajax in rails

南楼画角 提交于 2020-01-10 09:21:15
问题 I am using rails with jquery and ajax to check the availability of username. I am using the following plugin for jquery validation purpose. https://github.com/posabsolute/jQuery-Validation-Engine In my controller i am using the following method to check the username availability. def check_name name = params[:name] if name.strip == "" render :json => { :available => false } return end user = User.find(:first, :conditions => [ "name = ?", name]) if user render :json => ["name", false , "This