ruby-on-rails-3

Gmaps4rails - longitude and latitude in database no updated. <nested form>

家住魔仙堡 提交于 2019-12-23 12:26:43
问题 I have a model place with attributes name, state, longitude, and latitude. A model travel_plan has many places. I'm using nested form gem for places in the travel plan form. My problem is that the longitude and latitude were not updated when name and state were updated. In my place.rb belongs_to :travel_plan acts_as_gmappable def gmaps4rails_address "#{name},#{state}" end def gmaps4rails_infowindow "<h4>#{name}</h4>" end 回答1: The answer lies here. These two settings are particularly relevant

Howto set a default condition with fieldname on ransack?

送分小仙女□ 提交于 2019-12-23 12:18:50
问题 I have a user and a roles model, both are associated via habtm and there is a forum model associated to roles. In ransack search form for forums i want to filter by users who have a specific role (by name: moderator). Source looks like this: class User < ActiveRecord::Base has_and_belongs_to_many :roles, :join_table => :users_roles rolify class Role < ActiveRecord::Base has_and_belongs_to_many :users, :join_table => :users_roles belongs_to :resource, :polymorphic => true class Forum <

Capistrano deploy to different path on same server

若如初见. 提交于 2019-12-23 12:14:37
问题 I am trying to deploy my application using capistrano. But I want to deploy my application to multiple paths of the same server.For example If for the first run I want to deploy it to below path set :deploy_to, '/home/a/some_path/ Once completed the first one it should run for the second path that will be set :deploy_to, '/home/b/some_path/ and so on. Any suggestions how can I achieve this? Right now my single path deployment path is working AOK. 回答1: In your config file: set :deploy_to, ENV[

How does Rails populate the “model_type” field for polymorphic associations?

扶醉桌前 提交于 2019-12-23 12:09:37
问题 I have an Activity model. It belongs_to :parent, :polymorphic => true . Does Rails use parent.class.name , parent.model_name or something else to populate the parent_type field? I want a Presenter to behave like the parent object it wraps, and I need to override the right method. Thanks. 回答1: I'm working with Rails 3.0.7 right now, and the polymorphic type is being defined in active_record-3.0.7/lib/active_record/association.rb , line 1773. def create_belongs_to_reflection(association_id,

PG::Error: ERROR: permission denied for relation schema_migrations

十年热恋 提交于 2019-12-23 12:09:14
问题 Not sure why I'm running into this error. I've setup postgresql properly, just ran a migration and then rake db:migrate and I'm getting the title error. Here is my: database.yml development: adapter: postgresql encoding: unicode database: my_blog_development pool: 5 username: my_blog password: test: adapter: postgresql encoding: unicode database: my_blog_test pool: 5 username: my_blog password: production: adapter: postgresql encoding: unicode database: my_blog_production pool: 5 username: my

Refactoring Form_for Create Method for Comments in a Polymorphic Association

偶尔善良 提交于 2019-12-23 12:04:52
问题 I am working on my first polymorphic association relationship and I am having trouble refactoring my form_for create comments. I tried going through the Polymorphic Association RailsCasts http://railscasts.com/episodes/154-polymorphic-association?view=asciicast, but it seems dated. I have two questions: How do I rewrite my comment_form partial so that it would work for anything commentable? The way I have it right now, it would only work for traveldeals since (:commentable_id => @traveldeal

Pretty Print JSON generated with a jbuilder template in Rails 3.2.8

ⅰ亾dé卋堺 提交于 2019-12-23 11:52:34
问题 Anyone have a way to pretty print JSON output from jbuilder? I can pretty print JSON generated within a controller action with something like: JSON.pretty_generate(some_json_object) but once I pass off to a jbuilder template, I'm not aware of a way to have that output pretty printed. Right now, my action method's render statement is simple: render formats: :json And this successfully forces a rendering with jbuilder, regardless of input format type specified (which is my desired behavior).

“uninitialized constant Encoding” using rvm, ruby 1.9.2, bundler and passenger

大城市里の小女人 提交于 2019-12-23 11:45:12
问题 I am at wit's end here and am turning to you all for some help on this f*#$^ encoding issue. I am running on a private server with root permissions on Dreamhost. Here is a bit about my environment and versions. $ `which ruby` -v ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux] $ `which bundle` -v Bundler version 1.0.15 $ `which rails` -v Rails 3.0.9 Aside from this error, my rails app runs fine without issue. However, when I try to change the encoding a string by using the encode

“uninitialized constant Encoding” using rvm, ruby 1.9.2, bundler and passenger

蓝咒 提交于 2019-12-23 11:45:04
问题 I am at wit's end here and am turning to you all for some help on this f*#$^ encoding issue. I am running on a private server with root permissions on Dreamhost. Here is a bit about my environment and versions. $ `which ruby` -v ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux] $ `which bundle` -v Bundler version 1.0.15 $ `which rails` -v Rails 3.0.9 Aside from this error, my rails app runs fine without issue. However, when I try to change the encoding a string by using the encode

Rails checkbox and params

大兔子大兔子 提交于 2019-12-23 11:44:23
问题 I am using many checkboxes in a page as the following: <%= check_box_tag(:one, value = 1) %></p> Imagine that it goes from 1 to 20, all the same with the value changed. How can I get in the controller the params of the ones that were checked? Example: If user checks 3, 5 and 10 how can I get just those params in a single params? 回答1: You'll already get only the ones that were checked; unchecked boxes aren't sent to the server. 来源: https://stackoverflow.com/questions/7870090/rails-checkbox-and