Tag: ruby-on-rails-3

How can I use activerecord's query interface and scopes to identify the favorite in a race

I have two models Starter and Race. Starter belongs_to :race Race has_many :starters The attributes for Starter and race follow: Starter attributes: id, race_id, finish_position, odds Race: id, race_date, race_number, field_size I’m trying to accomplish two things: Select the favorite in each race. #for a particular race the Starter with the lowest odds* Select any […]

This Rails code works in Ruby 1.8.7 but not 1.9.2

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_step.step.step_quiz.id) : @quiz_attempt), :url => submit_quiz_course_course_step_path(@course_step.course, […]

Implementing chat in Rails

I am trying to implement a chat module in my rails application. I looked into this railscast Faye tutorial. More through the tutorial, Ryan mentions about broadcasting the messages but what I want is more like private conversations between the clients instead of broadcasting. Is it possible to do that through faye? or is there […]

ERROR – Could not load 'guard/rails-assets' or' ' find class Guard::RailsAssets (Rails 4/ zeus/guard)

I had a running app with no problem and just did bundle update and bundle install and now. I had not bundle updated for the past 4 months I think. and now when I run $ guard, I have this error: ERROR – Could not load ‘guard/rails-assets’ or’ ‘ find class Guard::RailsAssets I don’t understand […]

Form for adding children using ancestry gem

I have a user model in Rails and I am trying to use the Ancestry gem to add children to users. I would like to be able to enter one/several user ids (children) into a form and then assign them to be children to a user. I currently have a form for updating the name […]

Postgres: Error using GROUP BY and ORDER (on heroku)

I am trying to solve my heroku problem which it seems to have problem of We’re sorry, but something went wrong. We’ve been notified about this issue and we’ll take a look at it shortly. Is there any mistake I have and how to overcome it? How can I interpret these Heroku logs? ActionView::Template::Error (PGError: […]

AJAX call not working in Ruby on rails

I am learning ruby from the book “Agile web development with rails, 4th edtion” . I am using rails 3.2 and ruby 1.9.2 . I tried to make a call to the AJAX function of the card using the following code <%= button_to ‘Add to Cart’, line_items_path(product_id: product) , remote: true %> Then in the […]

Session variable not persisting after switch

I have tried to implement a switch between a basic and advanced viewing mode on a show page, essentially switching a basic/advanced div on/off through a link. In the controller I store the viewing-mode in a session variable (using a similar approach to http://railscasts.com/episodes/199-mobile-devices). Problem: the toggling works fine changing the viewing mode, but as […]

How to edit a model's attribute from the view of another associated model

I have a user model which has_one profile. The user model has a name attribute which is set when a user signs up. However, I want to let a user update that name attribute from the profile’s edit view. How can I do this?

Ruby on Rails: How to get tweets from the next_page using the Twitter search Api? And What should be my since_id and max_id?

Here is my code. I am trying to get the next page of results with @second_results. But it seems to just duplicate whatever is received from @first_results. search = TwitterManualSearch.new @first_results = search.first_query(:tag => params[:search]).results @second_results = search.second_query(:tag => params[:search], :since_id => @first_results.results.last.id, :max_id => @first_results.max_id).results For your reference I wrote some method to ease […]

Ruby is the best programming language in the world - Ruby on Rails.