Rails

Multiple objects in a Rails form

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to edit multiple items of my model photo in one form. I am unsure of how to correctly present and POST this with a form, as well as how to gather the items in the update action in the controller. This is what I want: The parameters are just an example, like I stated above: I am not sure of the best way to POST these values in this form. In the controller I want to something like this: @photos = Photo.find( params[photos] ) @photos.each do |photo| photo.update_attributes!(params[:photos][photo] ) end 回答1: In Rails 4, just this ...

Rails 3 - can't install pg gem

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I try to run bundle (bundle install), I all the time get Installing pg (0.13.2) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/ryan/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb checking for pg_config... no No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config checking for libpq-fe.h... no Can't find the 'libpq-fe.h header *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of

Bundler::GemNotFound: Could not find rake-10.3.2 in any of the sources

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have been working with Rails and it sends me back this error. Please provide questions. Thanks for all the help. I will update this question with a better one because I don't know how to ask it. Bundler::GemNotFound: Could not find rake-10.3.2 in any of the sources ~/.rvm/gems/ruby-2.0.0-p451/gems/bundler-1.6.2/lib/bundler/spec_set.rb:92:in `block in materialize' ~/.rvm/gems/ruby-2.0.0-p451/gems/bundler-1.6.2/lib/bundler/spec_set.rb:85:in `map!' ~/.rvm/gems/ruby-2.0.0-p451/gems/bundler-1.6.2/lib/bundler/spec_set.rb:85:in `materialize' ~/

Like button Ajax in Ruby on Rails

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Ruby on Rails project with a model User and a model Content , among others. I wanted to make possible for a user to "like" a content, and I've done that with the acts_as_votable gem. At the moment, the liking system is working but I'm refreshing the page every time the like button (link_to) is pressed. I'd like to do this using Ajax, in order to update the button and the likes counter without the need to refresh the page. In my Content -> Show view, this is what I have: <% if user_signed_in? %> <% if current_user.liked? @content %>

rails server bin/rails:6: warning: already initialized constant APP_PATH error

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've tried a number of things like uninstalling/reinstalling rails and gems but to no avail. When I go into my new project and run rails s or bundle exec rails server I'm getting this error: bin/rails:6: warning: already initialized constant APP_PATH /Users/toabui/Sites/cms/bin/rails:6: warning: previous definition of APP_PATH was here Usage: rails COMMAND [ARGS] Inside my bin/rails I see this code: #!/usr/bin/env ruby begin load File.expand_path("../spring", __FILE__) rescue LoadError end APP_PATH = File.expand_path('../../config

Ruby on Rails 3 - Reload lib directory for each request

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm creating a new engine for a rails 3 application. As you can guess, this engine is in the lib directory of my application. However, i have some problems developing it. Indeed, I need to restart my server each time I change something in the engine. Is there a way to avoid this ? Can I force rails to completely reload the lib directory or a specific file and his requirements for each request ? Thanks for your help :) 回答1: TL;DR put this in config/application.rb config.eager_load_paths += ["#{Rails.root}/lib"] remove require statements for

Ruby on Rails 3 - Reload lib directory for each request

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm creating a new engine for a rails 3 application. As you can guess, this engine is in the lib directory of my application. However, i have some problems developing it. Indeed, I need to restart my server each time I change something in the engine. Is there a way to avoid this ? Can I force rails to completely reload the lib directory or a specific file and his requirements for each request ? Thanks for your help :) 回答1: TL;DR put this in config/application.rb config.eager_load_paths += ["#{Rails.root}/lib"] remove require statements for

Pass a variable into a partial, rails 3?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a loop like such: <% @posts.each do |post| %> <% render middle %> <% end %> Then in my middle partial, how do I access the current post? 回答1: Try this: <% @posts.each do |post| %> <%= render 'middle', :post => post %> <% end %> Like this you'll have a local variable post available within the partial. 回答2: Give it to the partial as a local variable <%= render :partial => 'middle', :locals => { :post => post } %> Of course, rails also has a shortcut for rendering collections: <%= render :partial => 'post', :collection => @posts %> In

config.assets.compile=true in Rails production, why not?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The default Rails app installed by rails new has config.assets.compile = false in production. And the ordinary way to do things is to run rake assets:precompile before deploying your app, to make sure all asset pipeline assets are compiled. So what happens if I set config.assets.compile = true in production? I wont' need to run precompile anymore. What I believe will happen is the first time an asset is requested, it will be compiled. This will be a performance hit that first time (and it means you generally need a js runtime in production

No route matches [GET] /assets

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Rails app that I'm trying to test in the production environment. I ran RAILS_ENV=production rake assets:precompile which generated all of my assets in /public/assets. The problem is that when I start my app w/ RAILS_ENV=production rails s thin I get: ActionController::RoutingError (No route matches [GET] "/assets/application-eff78fd67423795a7be3aa21512f0bd2.css"): This file does exist though at /public/assets/application-eff78fd67423795a7be3aa21512f0bd2.css . Any thoughts as to why I'm getting this RoutingError ? 回答1: In production