ruby-on-rails-3

This Rails code works in Ruby 1.8.7 but not 1.9.2

自闭症网瘾萝莉.ら 提交于 2019-12-25 04:21:08
问题 Edit : This works: <%= form_for (@quiz_attempt.blank? ? QuizAttempt.new(:patient_id => current_user.id, :started => Time.now.utc, :step_quiz_id => @course_step.step.step_quiz.id) : @quiz_attempt), :url => submit_quiz_course_course_step_path(@course_step.course, @course_step) do |f| %> But this doesn't: (Trying to use form_for with as a function form_for() <%= form_for ((@quiz_attempt.blank? ? QuizAttempt.new(:patient_id => current_user.id, :started => Time.now.utc, :step_quiz_id => @course

Bootstrap Accordion Collapse not indexing divs correctly

别等时光非礼了梦想. 提交于 2019-12-25 04:19:28
问题 When trying to index divs so that the accordion buttons will collapse correctly, it's indexing every first contact in each category in my json file as 0 instead of indexing every contact no matter the category consecutively. Here's my erb file: <% @contacts.each do |category, hash| %> <div class="panel-group" id="accordion"> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"><%= category %></h3> </div> <div class="panel-body"> <ul class="list-group"> <% hash

Wrong number of arguments in as_json [`timeout` method is reserved!]

回眸只為那壹抹淺笑 提交于 2019-12-25 04:14:22
问题 I get an error in Rails that is related to one of my models, let's call it Unit . The following code produces an error: format.json { render :json => @units.as_json } The error is about wrong number of parameters (0 of 1). 回答1: I believe what you want is; def scheme @object = MonitoringObject.restricted_find params[:id], session[:client] @units = Unit.where("object_id = ?", @object.id) respond_to do |format| format.html format.json { render :json => @units[0] } end end Or, if you have your

How to get the value of include with conditions?

∥☆過路亽.° 提交于 2019-12-25 04:14:12
问题 I have three table say shop, item and item_type the shop contains names of shops and item contains items of each shop and item_type contains different types of that items along with the status such as available or not available. Now i want to render format.json { render json: {:shop => @shops.as_json(:include => :items)}} but based on the condition, say items with the item_type_id='1' and status of the item_type_status='available' 回答1: Try this: @shops = Shop.includes(:items).where("items

Javascript not loading latest submitted data

穿精又带淫゛_ 提交于 2019-12-25 04:14:05
问题 I recently asked this question: Javascript Form Submition? Now I'm trying to work out why, after form submission, the create.js.erb doesn't load the latest data (the data which was submitted). If I submit the data again, the table will update with the second last data but not the absolute latest. ...why? EDIT: Latest code - Categories controller: class Admin::CategoriesController < Admin::AdminController ... def create @category = Admin::Category.new(params[:admin_category]) # You can't

Math with datetime in SQL query in rails

核能气质少年 提交于 2019-12-25 04:12:04
问题 So I have an table of phone_numbers in Rails 3.2, and I would like to be able to make a query such as the following: PhoneNumber.where("last_called_at - #{Time.now} > call_spacing * 60") where last_called_at is a datetime and call_spacing is an integer, representing the number of minutes between calls. I have tried the above, I have also tried using PhoneNumber.where("datediff(mi, last_called_at, #{Time.now}) > call_spacing") If anyone could help me make this work, or even recommend a current

How to sort with elasticsearch?

人走茶凉 提交于 2019-12-25 04:08:11
问题 I am trying to make methods for sorting desc and asc . I am using rails, tire gem and elasticsearch. I am trying to figure out what sort params I can send in the URL So I have defined in the search-block that it is sorting the result desc order. sort { by :price, "desc"} When a user search for apartments in: new-york the result is sort desc order. The search query/URL looks like this: http://localhost:3000/apartmens?utf8&query=newyork Why cant I add a sort-params in the url, like this: http:/

jruby IO.popen read hangs in action when requests are made to the local dev server

大城市里の小女人 提交于 2019-12-25 04:06:47
问题 I just want to send the output of wkhtmltopdf to the user. It shouldn't be so hard. def it send_pdf "file.pdf" end def send_pdf(file) url= url_for(params) # Example: http://localhost:3000/report/it webkit= Rails.root.join('app', 'bin', 'wkhtmltopdf', 'current') cmd= "#{webkit} -q \"#{url_for(params)}\" -" data= IO.popen(cmd).read ############### HANGS HERE ################### send_data(data, type: "application/pdf", filename: file) end Why does it hang and how to fix it? 回答1: I think the clue

Trouble on evaluating other model data

纵饮孤独 提交于 2019-12-25 04:06:20
问题 I am using Ruby on Rails 3.0.9 and RSpec 2. In my spec file I have code like the following: describe User do let(:authorizations) { Authorization.all.map(&:name) } it "should have a 'registered' value" do authorizations.should include("registered") end end When I run the above test I get: User should have a 'registered' value Failure/Error: authorizations.should include("registered") expected [] to include "registered" Diff: @@ -1,2 +1,2 @@ -registered +[] Is it possible to solve the above

Mass assignment warning when using nested attributes

旧街凉风 提交于 2019-12-25 04:03:46
问题 I am quite new to both programming and ruby on rails. I have followed http://ruby.railstutorial.org/ and then i have started to watch episodes from http://railscasts.com. What i am trying to do is that "Handling multiple models in a single form". Below you will see my models and their assosications and also the view of form that i am trying to get info from users. My modelling is that; There are employers, employers have interviews and interviews have questions. Customquestion model: class