ruby-on-rails-3.2

Image url in JSON (RABL, Dragonfly, Ruby on Rails)

自作多情 提交于 2019-12-10 23:47:58
问题 I'm using RABL gem, my user model has many posts users/show.rabl object @user attributes :id, :name child :posts do extends "posts/post" end posts/_post.rabl attributes :id, image: post.image.url I want to show post's image, but i have an error: undefined local variable or method "post" . But in posts/_post.html.erb i can use this <%= post.image.url =%> Images loaded by dragonfly gem. How can i get this image url in json format? 回答1: If this is a child-attribute you can append it back to the

Rails 3.2.1: Calling undefined method in view causes test to hang for 30+ seconds

ぐ巨炮叔叔 提交于 2019-12-10 23:29:38
问题 I'm upgrading my app from 3.0.9 to 3.2.1 (ruby 1.9.3-p0, rvm, bundler) and one thing that I haven't been able to track down yet is this problem. I have a controller spec (in spec/controllers) that renders views for each example. The template that it renders can have any undefined method (like calling "- blahblah" in the haml) and it causes the test to hang for over 30 seconds. Here is the error: undefined local variable or method `blahblahblah' for #<#<Class:0x007fa84f76cc90>:0x007fa849c578c8

Rails namespacing error?

亡梦爱人 提交于 2019-12-10 21:52:29
问题 I have this in my config/routed.db : namespace :admin do resources :users resources :events end I generated the User model by using the scaffolding Rails provides, then I simply generated a admin/admin controller by using Rails' generate and simply moved all the user-related stuff into the admin sub-directories inside the controllers/views/helpers. Yes, I did have to add admin_ in a few places and inside the form partial I had to change the form_for(@user) to form_for([:admin, @user]) . When

mongoid polymorphic association error

我怕爱的太早我们不能终老 提交于 2019-12-10 20:37:25
问题 I'm having some problems using mongoid-3.0.6 with polymorphic fields. Using rails 3.2.8 and ruby 1.9.3 Using a normal polymorphic relation: class Shirt include Mongoid::Document field :name, localize: true belongs_to :itemizable, polymorphic: true end class Item include Mongoid::Document field :price, type: Float field :quantity, type: Integer, :default => 1 has_one :product, as: :itemizable accepts_nested_attributes_for :product end The same association is available through the metadata: >>

Rails helper method: Nested hash to nested HTML list

社会主义新天地 提交于 2019-12-10 20:31:17
问题 I am trying to write a Rails helper method to convert a nested hash into a nested HTML list. For example: { :parent => "foo", :children => [ { :parent => "bar", :children => [ { :parent => "baz", :children => [] } ] } ] } should become: <ul> <li>foo</li> <ul> <li>bar</li> <ul> <li>baz</li> </ul> </ul> </ul> The hash may have any number of levels, and any number of parents per level. What is the best way to achieve this please? 回答1: You can make a recursive method to render to hash to a nested

attempting to execute any command starting “rails” yields “Could not locate Gemfile”

旧街凉风 提交于 2019-12-10 20:10:48
问题 I am trying to install a new rails app. I've already got several rails apps on my machine, all working fine. $ rails new app Could not locate Gemfile Then I figured I'd run a trace to figure out what was going on, as you wouldn't expect to have a Gemfile at this point anyway, as typically the above command would create an entire new rails app in a directory named app with the Gemfile contained within that directory. $ rails new app --trace Could not locate Gemfile So I tried to reinstall

How to reload files in app/models/subdirectory in dev environment for STI

微笑、不失礼 提交于 2019-12-10 19:07:21
问题 I implemented STI in one of my models, using some tips from Alex Reisner's blog post. I already had all my subclasses use the superclass's controller, with serialize/store to hold the extra attributes. I added the model_name and self.select_options methods to the superclass, and the preload initializer from Alex's blog. I also changed my collection_select in the _form view helper and attribute validation to use the self.select_options method. All my subclasses are in individual files in a app

Rails wicked gem redirect with params

半腔热情 提交于 2019-12-10 18:27:02
问题 I am using the wicked gem to build a form wizard. In the documentation, it is using the current_user object but I want to use a different object. I am struggling with adding a parameter to redirect_to so I can use this object. products_controller.rb def create @product = current_user.product.build(params[:product]) @product.ip_address = request.remote_ip if @product.save redirect_to product_steps_path # This is where I think I need to pass product object but not sure how else render 'new' end

Custom Views Scaffolding in Rails Engines

烂漫一生 提交于 2019-12-10 17:44:06
问题 I'm trying to get custom scaffolding working from my engine. I followed some tutorial on customizing Rails 3.2 scaffolding in a normal Rails App and put my customized templates in the engines /lib/templates/erb/scaffold directory but they don't get picked up by the app that includes the engine. Any suggestions? Update: I also tried to override the Rails ScaffoldGenerator's source_path and tried some other paths to put my template in, like: lib/rails/generators/erb/scaffold/templates 回答1: In

Undefined method 'accept' for nil:NilClass after upgrading to Rails 3

随声附和 提交于 2019-12-10 17:28:16
问题 I just upgraded my Rails application from Rails 2.3.8 to Rails 3.2.7 and I've run across a problem with Activerecord. If I try to access my database with Activerecord at all(Ex: Employee.last), I get the following error: NoMethodError: undefined method `accept' for nil:NilClass from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems/activerecord-3.2.7/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `to_sql' from /home/aneyer/.rvm/gems/ruby-1.8.7-p370@rails3/gems