ruby-on-rails-3

js + rails - can't get this form working

故事扮演 提交于 2019-12-25 07:09:37
问题 I adapted this js from this SO question, but I've never used js before and not sure what I'm doing wrong here. It's very possible it's a simple fix, but your help is hugely appreciated. The goal : When a user adds a class, they put in the name, the type, and the number of students. When :number_of_students changes, the js kicks in and shows the appropriate number of forms_for student (the example i'm working from). The problem : Overall it's working - the view works, and submitted data goes

rails : How can I call methods in the nested model from parents?

末鹿安然 提交于 2019-12-25 07:08:41
问题 This is my model. Survey class Survey < ActiveRecord::Base belongs_to :user has_many :questions, :dependent => :destroy accepts_nested_attributes_for :questions, :reject_if => lambda {|a| a[:content].blank?}, :allow_destroy => true Question : there is is_correct(boolean) column which indicates whether students get the right answer or not. class Question < ActiveRecord::Base belongs_to :survey has_many :answers, :dependent => :destroy accepts_nested_attributes_for :answers, :reject_if =>

rails : How can I call methods in the nested model from parents?

不问归期 提交于 2019-12-25 07:07:03
问题 This is my model. Survey class Survey < ActiveRecord::Base belongs_to :user has_many :questions, :dependent => :destroy accepts_nested_attributes_for :questions, :reject_if => lambda {|a| a[:content].blank?}, :allow_destroy => true Question : there is is_correct(boolean) column which indicates whether students get the right answer or not. class Question < ActiveRecord::Base belongs_to :survey has_many :answers, :dependent => :destroy accepts_nested_attributes_for :answers, :reject_if =>

Rails Devise - Update column from another controller

六月ゝ 毕业季﹏ 提交于 2019-12-25 07:00:37
问题 Rails 3.0 Following these instructions: https://github.com/plataformatec/devise/wiki/How-To%3a-Require-admin-to-activate-account-before-sign_in I've generated a migration :approved (boolean) for my devise user.rb. Now I want to edit it with a checkbox from a different controller: unapproved_users_controller.rb. When I load the form in the edit I get this error: undefined method `user_path'. routes.rb , the resources for my new controller resources :unapproved_users app/models/user.rb , notice

Select many box for HABTM

坚强是说给别人听的谎言 提交于 2019-12-25 06:59:04
问题 I have two models; question and category which have a HABTM association between them. Now I want to have a form where I can edit the questions categories, however I don't know how. I started with this but I am lost, I am unsure on what to name the "name" attributes etc and how it is automatically edited/created with the question, how do I set this up? <%= f.fields_for :categories do |categories_form| %> <%= categories_form.select "category_ids", Category.all.collect { |c| [c.description, c.id

How to create factories with attr_accessible?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 06:58:29
问题 How to deal with factories and attr_accessible ? My example: # model class SomeModel attr_accessible :name, full_name, other_name end #spec require 'spec_helper' describe "test" do it do create(:some_model, name: "test name", user: User.first) #factory end end #error ruby(17122,0x12a055000) malloc: *** error for object 0x8: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug I think the error is because user_id is not in attr_accessible attributes. 回答1:

Problems with limit method in Rails 3.2 and hash ordering

ぃ、小莉子 提交于 2019-12-25 06:57:55
问题 I have a database with cities which has_many :businesses I want to display a list of 20 cities. These 20 cities should be the ones with the most businesses. Only if there are less than 20 cities with at least one business I add the cities with the most inhabitants to this list of 20 cities. Since the cities are ordered by inhabitants in my database I can simply take the first ones by id in this case. My query now is: popularcities = City.order("businesses_count desc").limit(20) businesses

OAuth2 Provider: How to offer a login page in order to let oauth clients get the resource owner id

让人想犯罪 __ 提交于 2019-12-25 06:50:01
问题 I'm developing a RESTful API in Rails3 and a corresponding OAuth2 provider (consumed by android clients). I supply the typical routes: authorize => Authorization Grant token => receive access_token All this is working and my mobile clients receive and save the access tokens for the resource owners. But now, how do I inform the mobile client about who is currently using the app and which access_token it has to use from the database? I need a login page and then perhaps send the user's id to an

Can anyone recommend a gem for searching that actually allows me to easily filter my results in ruby on rails?

偶尔善良 提交于 2019-12-25 06:46:49
问题 I've tried thinking sphinx after being pointed in that direction and simple filtering seems impossible. I've googled and asked questions for 2 days now and it seems it can't be done which is shocking because it's something commonly done when searching on websites. All I would like to do add filtering options to my search form such as filtering by one or a combination of: When user hits browse page all the sites users are returned but showing 20 results per page Filtering options in: location

Rails geocoder gem issues

为君一笑 提交于 2019-12-25 06:39:55
问题 I am using the geocoder gem and I need to code a start and end address for a model, however I am not sure if I can accomplish this using this gem and if I can whether I am doing it correctly. If this cannot be done with the gem, is there another resource that will allow me to geocode two locations on the same form? This is an example of what I am trying to do, but it just passes the second address to be geocoded. geocoded_by :start_address before_validation :geocode geocoded_by :delivery