ruby-on-rails-3.1

LEFT OUTER JOIN with conditions (where, order by)?

时光怂恿深爱的人放手 提交于 2019-12-12 09:39:43
问题 I'm working on a Rails3 project with MySql (local) and Postgresql (Heroku) databases. I need to put conditions on a LEFT OUTER JOIN but I don't know how. I have 2 tables TRAININGS and TRAINING_HISTORIES. I want to retrieve all the records of TRAININGS and add the last valid (aka finished) associated record of TRAINING_HISTORIES. table TRAININGS id name order_by 5 A 1 6 B 2 7 C 3 table TRAINING_HISTORIES id training_id finished_at score 43 5 2011-06-06 10 44 5 null null 45 6 2011-07-07 11 46 6

Rails assets don't get updated

陌路散爱 提交于 2019-12-12 09:35:44
问题 I have a Rails 3.1 app and for some reason when I change CSS, the changes don't show up. I did bundle exec rake assets:precompile and it helped once, but now I am stuck with the old CSS no matter what. 回答1: As your assets are now precompiled you need to clean them with the following bundle exec RAILS_ENV=development rake rails_group=assets assets:clean 回答2: You might want to try rake assets:clean and then rake assets:precompile 回答3: For my production environment I had to combine a few of the

What is good way to limit the amount of comments shown to a user until they choose to view all?

自闭症网瘾萝莉.ら 提交于 2019-12-12 09:11:07
问题 Currently I have an each loop in the template for where the comments are display. Say a user has 50 comments to a micropost they have posted. A long list showing 50 comments will be displayed. To save space on the page I've decided I'd like to limit comments shown to 2-3 per micropost. If a user wishes to view more they can click "view more" or "view all". I'm wondering how a server would cope if there were like 10,000 comments and a user clicked "view all" which is why I may choose to

Having difficulty installing ruby-filemagic gem on new RHEL6 server

荒凉一梦 提交于 2019-12-12 08:23:24
问题 It appears to be looking for the libmagic.so.1 file. I have that file. It is located in /usr/lib64. I am not running this installation as the root user. I am also using rvm and Bundler. This is the result of my "bundle" command, when it gets to the ruby-filemagic line in my Gemfile: [server@mine ext]$ ruby extconf.rb --with-magiclib checking for magic_open() in -ltrue... no *** ERROR: missing required library to compile this module *** extconf.rb failed *** Could not create Makefile due to

ruby on rails how to deal with NaN

北慕城南 提交于 2019-12-12 07:24:34
问题 I have read few posts regarding NaN but did not figure out how to deal with it in Ruby on Rails. I want to check a value if it is a NaN I want to replace it with Zero(0). I tried the following logger.info(".is_a? Fixnum #{percent.is_a? Fixnum}") when percent has NaN it returns me false. I have made few changes in the logger logger.info("Fixnum #{percent.is_a? Fixnum} percent #{percent}") Output Fixnum false percent 94.44444444444444 Fixnum false percent NaN Fixnum false percent 87.0 回答1: NaN

multiple occurences of jquery dialog boxes on table rows in rails 3 - how do I do this?

谁说我不能喝 提交于 2019-12-12 05:54:04
问题 The task I'm trying to accomplish: I have a Rails 3 application that processes work orders for a telecommunications company. The index page of the work orders controller displays paginated work orders in rows of up to 30 per page. There are two fields that the client would like to be able to update from this page. They are Technician ETA and Work Order Status . I've written some code to use jquery dialog popups to serve partial forms (one for each field) for update. So far I've been able to

save 2 items in db in 1 controller method(rails )

我的梦境 提交于 2019-12-12 05:39:37
问题 i have a problem with saving 2 items in db at one moment(i am using rails 3.1). I have model Message class Message < ActiveRecord::Base belongs_to :user validates_presence_of :content end Message model have params: user_id(reciever), user_from(sender), and content(text) and model User is class User < ActiveRecord::Base has_many :posts has_many :messages end in MessagesController i have method def create @message =Message.new(params[:message]) User.find(@message.user_id).messages.build(params[

How do I stop a flash error message from showing on page load until after button is clicked in ruby on rails?

丶灬走出姿态 提交于 2019-12-12 05:36:40
问题 I'm trying to figure out a way to stop this flash message from showing on page load: class SearchesController < ApplicationController def index @users = User.search params[:search] @default_image = "/assets/default_avatar.jpg" if @users.empty? || params[:search].blank? flash[:error] = "Sorry no user(s) found!" if @users.empty? flash[:error] = "Please give us something to search for!" if params[:search].blank? render 'index' end end end I understand why it's showing (obviously when page is

Add custom user roles spree 1.3.1

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:07:42
问题 I am using spree 1.3.1 and Devise gem for authentication and i need to add a user_role called as " partner " who can see orders in admin area but can't create/edit/update/delete any of the orders. Thanks in advance 回答1: Having app/models/partner_ability.rb file. Then use the following role based read permissions for role partner - class PartnerAbility include CanCan::Ability def initialize(user) user ||= User.new if user.has_role? "partner" can :read, Product end end end Also add the

Getting rid of form and use just button to create new record

这一生的挚爱 提交于 2019-12-12 04:49:55
问题 Rails 3.1. I have the following: // _form.html.erb <%= form_for ([@country, @state], :remote => true) do |td| %> <div id= "state_errors" style="display:none"></div> <%= td.text_field :position, :id => "next_state" %> <div class="actions"> <%= td.submit %> </div> <% end %> // global.js function nextState() { Array.max = function( array ) { return Math.max.apply( Math, array ); }; var getLastState = $("input.sortable_state_item_position").map(function() { return $(this).val(); }).get();