ruby-on-rails-3

Factory Girl with has many relationship (and a protected attribute)

我的梦境 提交于 2020-01-04 04:02:44
问题 I have this kind of relation: class Article < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :article attr_protected :article_id end The default scenario inside controllers looks like: @article = Article.create(:title => "foobar") @comment = @article.comments.create(:content => "w00t") I had tried to write those factories: Factory.define :article do |f| f.title "Hello, world" end Factory.define :comment do |f| f.content "Awesome!" f.association

Help with PDFKit and Rails App

◇◆丶佛笑我妖孽 提交于 2020-01-04 03:55:07
问题 Working on Ubuntu 10.04 Lucid webserver (linode). Followed these instructions to install wkhtmltopdf link (only one that worked for me.) I can run wkhtmltopdf http://www.google.com google.pdf and it works. Anything from my rails app generates a 500 error. apache error.log /bin/wkhtmltopdf: symbol lookup error: /bin/wkhtmltopdf: undefined symbol: _ZN9QListData11detach_growEPii rails log Rendered customers/agreement_form.html.erb (15.0ms) Completed 200 OK in 19ms (Views: 16.6ms | ActiveRecord:

undefined method `flash' for #<ActionDispatch::Request

丶灬走出姿态 提交于 2020-01-04 03:52:09
问题 I have stuff with Ruby on Rails 3 I try this simple code def index flash[:notice] = "ok" respond_to do |format| format.html # index.html.erb end end it does not work NoMethodError in DashboardsController#index undefined method `flash' for #<ActionDispatch::Request:0x7fee9329a9d0> When I try redirect_to :some_in, :notice => "ok" in other place (in some_controller.rb) and then print this :notice in .erb I have same error, undefined method `flash' I'm stuck on this. I used google to search for

Rails 3.1 SASS asset helpers not not including RAILS_RELATIVE_URL_ROOT / relative_url_root

微笑、不失礼 提交于 2020-01-04 03:11:49
问题 I have been working on an upgrade to Rails 3.1 from 2.3.11. One of the main hurdles to clear is the conversion to the asset pipeline. In this process I decided to convert my css to sass (scss). In rails 3.1 all assets delivered through the pipeline receive a hash appended to the filename in production. Because of this, all the images referenced in my css now needed to use the image-path or image-url helpers in sass. The issue is, that even though I have set my ENV['RAILS_RELATIVE_URL_ROOT']

Rails 3.1 SASS asset helpers not not including RAILS_RELATIVE_URL_ROOT / relative_url_root

主宰稳场 提交于 2020-01-04 03:11:22
问题 I have been working on an upgrade to Rails 3.1 from 2.3.11. One of the main hurdles to clear is the conversion to the asset pipeline. In this process I decided to convert my css to sass (scss). In rails 3.1 all assets delivered through the pipeline receive a hash appended to the filename in production. Because of this, all the images referenced in my css now needed to use the image-path or image-url helpers in sass. The issue is, that even though I have set my ENV['RAILS_RELATIVE_URL_ROOT']

PDF attachment in email is called 'Noname'

≯℡__Kan透↙ 提交于 2020-01-04 02:55:34
问题 When I send an email with a attached pdf file the email only shows a file called 'Noname'. The file itself is the multipart section of the email with the base64 attached pdf. How can I send the PDF so it comes up as an attachment and doesn't corrupt the email? Here is my code: attachments['126539_statistics.pdf'] = File.read("app/assets/pdfs/126539_statistics.pdf") mail(:to => email, :subject => subject, :body => message, :content_type => 'application/pdf') 回答1: I had face same problem. I

Eager-loading association count with Arel (Rails 3)

纵然是瞬间 提交于 2020-01-04 02:55:26
问题 Simple task: given that an article has many comments, be able to display in a long list of articles how many comments each article has. I'm trying to work out how to preload this data with Arel. The "Complex Aggregations" section of the README file seems to discuss that type of situation, but it doesn't exactly offer sample code, nor does it offer a way to do it in two queries instead of one joined query, which is worse for performance. Given the following: class Article has_many :comments

generate HTML <select> with title inside each <option> to apply the msDropDown plugin

我只是一个虾纸丫 提交于 2020-01-04 02:53:23
问题 I am using the carrierwave gem to upload images to my application. Now I need to display the images in a dropdown list that is part of a form. I am trying to use the msDropDown. However, I need to generate a title="#path for the image" inside each <option> of my <select> . At the moment I have: <%= f.select(:style_id, Style.all.map{ |p| [p.dropdown, p.id] }, {:include_blank => 'Select Style | Construction'}, class: "bigselect" ) %> The above generates the following HTML: <select class=

Routing error with Rails 3 with members

主宰稳场 提交于 2020-01-04 02:49:27
问题 I have the following route in rails 3: resources :jobs do member do post :seller_job_submitted end end And the following form =form_for job, :url=>seller_job_submitted_job_path(job), :remote=>true do |f| I know it's not very restful, but it's kind of a stop gap for now. In any case, I keep getting this error when submitting the form Started POST "/jobs/74/seller_job_submitted" for 127.0.0.1 ActionController::RoutingError (No route matches "/jobs/74/seller_job_submitted"): but when I run rake

custom sign in for devise

倖福魔咒の 提交于 2020-01-04 02:46:09
问题 Now I am using the devise gem, and after successful authorization it redirects user to the root page. How to modify sign_in action to return json array like this: {"auth_result":"1"} instead of redirect? Is it possible? I haven't found recipes for these in devise wiki. 回答1: Devise currently does not handle JSON responses - see the issue on github. Therefore you would have to create a custom sessions_controller to handle your response. Take a look at the implementation on github to get an idea