ruby-on-rails-3

Private pub issue in rails application

99封情书 提交于 2020-01-07 06:53:28
问题 I have article model and i want to show a notification such as a flash message on the home page to the users when they log in or who is logged in already when a new article is posted using private_pub gem articles_controller.rb class ArticlesController < ApplicationController def index @articles = Article.all @articles_grid = initialize_grid(Article, :include => [:user]) end def show @article = Article.find(params[:id]) @comment = Comment.new end def new @article = Article.new end def create

has_many through with condition not working

爱⌒轻易说出口 提交于 2020-01-07 06:28:09
问题 I have a model Grade and a model User. Between grades and user is a many-to-many association through collaborations. in user.rb has_many :grades, through: :collaborations, source: :user works, but i need to get only grades with attribute "archived" = false i tryied has_many :grades, through: :collaborations, source: :user, conditions: [' archived = ? ', false] but it takes all the grades, in other words, the condition is ignored. I can put in my collaborations this condition, but

“Can't initialize a new Rails application within the directory of another, please Type 'rails' for help.”

早过忘川 提交于 2020-01-07 06:20:00
问题 I'm just starting out with rails and I'm practicing the basic ruby commands, one of which is the rails new myproject command. My projects are under the Aptana workspace directory where I've used the command line and Aptana both to create projects there. After a few creations and rails s commands and deletions, I've started getting this error message when I try to generate a new rails project: "Can't initialize a new Rails application within the directory of another, please Type 'rails' for

Ancestry Gem 'undefined method' error

蹲街弑〆低调 提交于 2020-01-07 06:16:17
问题 I am using the Ancestry Gem and I am getting an undefined method "arrange" for #<Array:0x007f8d58e58700> error with the following code: <%= @shipmgr_carriers.arrange(:order => :name) %> However, When I just output @shipmgr_carriers I get an array with ancestry: [#<Shipmgr::Carrier id: 9, name: "testing", status: nil, created_at: "2012-01-16 22:44:28", updated_at: "2012-01-16 22:44:28", ancestry: nil>, #<Shipmgr::Carrier id: 10, name: "test", status: nil, created_at: "2012-01-16 22:44:28",

Ancestry Gem 'undefined method' error

て烟熏妆下的殇ゞ 提交于 2020-01-07 06:16:06
问题 I am using the Ancestry Gem and I am getting an undefined method "arrange" for #<Array:0x007f8d58e58700> error with the following code: <%= @shipmgr_carriers.arrange(:order => :name) %> However, When I just output @shipmgr_carriers I get an array with ancestry: [#<Shipmgr::Carrier id: 9, name: "testing", status: nil, created_at: "2012-01-16 22:44:28", updated_at: "2012-01-16 22:44:28", ancestry: nil>, #<Shipmgr::Carrier id: 10, name: "test", status: nil, created_at: "2012-01-16 22:44:28",

Rails: Reset a model attribute at specific time each day

≡放荡痞女 提交于 2020-01-07 05:38:30
问题 I have a rails app with a Location model, which has a rating , and a rating_count field. Now, I need to reset every Location 's rating and rating_count attributes to 0 at a specific time everyday, lets say 12:00:00 UTC. How would I accomplish this? I'm using the default sqlite3 databases. 回答1: The best option is to use cron. You can find tons of documentation out there!Although if you are running a Rails app you should check out whenever a pretty neat gem for managing cron jobs for your app!

concatenate link_to with pipe

痞子三分冷 提交于 2020-01-07 05:37:04
问题 I want to concatenate a few links with a pipe. But all links are surrounded by an if-statement. Example: - if condition1 = link_to link1 - if condition2 = link_to link2 - if condition3 = link_to link3 If condition 1 and 2 are true, the result should be link1 | link2 Any hints how to do this? 回答1: I would use smth like that for that purpose: = [[l1, c1], [l2, c2], [l3, c3]].map{ |l, c| link_to(l) if c }.compact.join('|') or = [(link_to(l1) if c1),(link_to(l2) if c2),(link_to(l3) if c3)]

Transformation of query to active record

安稳与你 提交于 2020-01-07 05:34:08
问题 To perform a range query we follow something akin to the syntax below -: oms[:order_items].where(:internal_sla => 3..5) results in this query => #<Sequel::Mysql2::Dataset: "SELECT * FROM `order_items` WHERE ((`internal_sla` >= 3) AND (`internal_sla` <= 5))"> But how can I change the active record query to give me something like this => select internal_sla from order_items where (internal_sla<=3 and internal_sla>=0) OR (internal_sla<=15 and internal_sla>=10) 回答1: .where("(internal_sla >= ? AND

jQuery “return false” works in version 1.6 but not 1.6.1 (rails 3)

十年热恋 提交于 2020-01-07 05:10:26
问题 The following code used to function without attempting to render a new template with jQuery verion 1.6. I installed jQuery 1.6.1 and now a radio button click results in an attempt to render a new page. FYI, the form was submitted on each click because quite a few clients would complete part of the questions, close the browser and expect their work to be there when they came back to finish. If there is a better way, I'd love to know it. in the application.js on development machine: $('

RoR: 'nil' is not an ActiveModel-compatible object that returns a valid partial path

风流意气都作罢 提交于 2020-01-07 04:58:07
问题 ok so I am trying to display a users microposts in two different places based on a hidden_tag_field that is a column in the database called kind. This kind is either "purchase" or "micropost". The app/views/users/show.html.erb (where I want both lists to be displayed) <section> <div id= "purchases"> <%= render 'shared/micropost_form_purchase' %> <div class="row"> <div class="span8"> <% if @user.microposts.any? %> <ol class="microposts"> <%= render @purchases %> </ol> <% end %> </div> </div> <