ruby-on-rails-3

Rails Question: belongs_to with STI — how do i do this correctly?

我怕爱的太早我们不能终老 提交于 2020-01-02 01:02:24
问题 I've been playing around with STI and belongs_to / has_many relationships and I'm a bit confused. I have a few questions based on a model configuration similar to: class Parental < ActiveRecord::Base end class Mother < Parental has_many :babies end class Father < Parental has_many :babies end class Baby < ActiveRecord::Base belongs_to :?????? end What should Baby belong_to? In terms of a migration, what should i name/add for foreign key on the babies table? I've had a hard time researching

How do I connect to Gmail's IMAP server using oauth in Rails3?

此生再无相见时 提交于 2020-01-02 01:00:14
问题 I found the gmail_xoauth gem, which does most of what I need, but I also need to generate the oauth tokens (consumer_key and consumer_secret) from inside Rails3. I am trying to integrate Gmail's oauth integration into my site and hence cannot use the python script that the above gem refers to. I would like my site to take the user to the authentication page and extract the consumer_key/secret tokens. I am new to OAuth, so maybe there's something obvious that I am missing. UPDATE: I solved the

Rspec Testing of real time results through mTurk

删除回忆录丶 提交于 2020-01-02 01:00:10
问题 I am creating hits at mTurk through Rspec test code but at the same time i need to test the results which must be send back from mTurk. In order to save complexity testing for every test i'm using VCR to record the HTTP Requests in a cassette. How can i implement this test?? 回答1: well i did some hack for that, i used debugger to hold my rspec test until results comes back from mTurk and then it get stored in VCR. so i have to do this kinda hack once and then after that VCR works for me 来源:

Rails link_to destroy a nested resource?

独自空忆成欢 提交于 2020-01-02 00:47:13
问题 I have a nested resource attachments and I want to create a link_to to destroy/delete the attachment. Here's what I have, but it is posting as a GET versus a PUT: <%= link_to "Delete Attachment", project_thread_attachment_path(@attachment.thread.project.id, @attachment.thread.id, @attachment.id), :confirm => "Are you sure you want to delete this attachment?", :method => :delete, :action => "destroy" %> Ideas? Thanks! 回答1: You should be able to use the following by itself (remove the :action =

ruby - rails - Dealing with a Boolean False- It outputs nothing

廉价感情. 提交于 2020-01-02 00:31:06
问题 I have record in my db that is a boolean field (true/false). The field is archived. When archived is true all these work great to output true: Rails.logger.info @commentable.archived Rails.logger.info @commentable.archived? Rails.logger.info !!@commentable.archived? BUT when the archived is false, it outputs nothing for either of the above. How can I get an output of false when the field is FALSE? Thanks 回答1: Try .to_s on the field? irb(main):001:0> false.to_s => "false" irb(main):002:0> true

NameError (undefined local variable or method `devise_parameter_sanitizer'

为君一笑 提交于 2020-01-01 23:54:11
问题 I'm using devise for user authentication. However, when a user tries to create an account I am getting this error: NameError (undefined local variable or method `devise_parameter_sanitizer' This is what my devise registrations controller looks like: def sign_up_params devise_parameter_sanitizer.for(:sign_up) end Any ideas? Thanks in advance 回答1: try to use rails4 branch gem 'devise', github: 'plataformatec/devise', branch: 'rails4' 回答2: Looking at the devise open issues on Github i found this

Rails ajax rating help how to create a helper method to display stars

泄露秘密 提交于 2020-01-01 22:28:53
问题 I am creating, some simple Ajax rating. Based on the first answer on this question Rails 3 rateable model - How to create ajax rating? And the partial for the rating, called _rating.html.erb , was something like: <%= form_tag url_for(controller: 'items', action: 'rate', id: item.id), remote: true %> <%= rating_stars(item.rating_score, item.ratings) %> <%= item.ratings %> Votes </form> In this partial, the rating_stars() helper method generated some kind of star-like representation for the

Artists Group_by nested attribute Order_date

旧城冷巷雨未停 提交于 2020-01-01 19:56:32
问题 I have created a functioning e-commerce platform where Members can buy songs. Everything works fine, But I would like to group all of my Orders in my Index Page by Month. Currently I am able to group each Album with its corresponding Artist, and each Ordered Song to its corresponding Album. But now I would like to group Orders by Month. How Can I Group Artists by the order_date in my Orders Table, So that everything is organized by Month? Ex. of what I've like to do Month 1 Orders Artist1

Rails 3 - Periodic Refresh of DIV

只谈情不闲聊 提交于 2020-01-01 19:55:14
问题 I am trying to refresh the contents of a div using AJAX/Unobtrusive JavaScript/JQuery. This is easy to do if I make a "refresh" link and give it a data-remote attribute. However, I would like to refresh every 2 seconds using the setInterval function rather than using a link. This code should demonstrate what I'm trying to do. It does not work when put in application.js because the ERB is not evaluated, but hopefully it will explain my goal. setInterval(function(){ $("#scuttlebutt").html("<%=

How can I create multiple instances of an assosiated model from a rails 3 form_for when I don't know how many I'm going to add?

大城市里の小女人 提交于 2020-01-01 19:49:29
问题 I have a form_for that creates a new 'Estimate' and each of these estimates can have an unlimited number of 'Items' (this is like a part number, but it will have it's own set of attributes). I would like to be able to create as many instances of the associated Items model as I want to before I submit the form that creates the new Estimate, and then have it create all of the associated Items that go with that Estimate. I've read a lot in the API on form_for and accepts_nested_attributes_for, I