ruby-on-rails-3

rails 3 does not render jquery properly

♀尐吖头ヾ 提交于 2020-01-17 07:57:08
问题 i have https://github.com/tkrotoff/jquery-simplecolorpicker-rails and i have tried https://github.com/tkrotoff/jquery-simplecolorpicker in plain HTML and the plain HTML worked. I had swapped the code from the HTML to the one in rails but all my jquery functions does not work at all. The file colorselect.js $(function(){ $('#print_colorpaper').simplecolorpicker(); }); colorpaper.html.erb <%= f.select(:colorpaper, Print::MY_COLORS, :selected => '#fbd75b') %> the only thing i see in rails is the

How to make 'create' method be useable from outside

心不动则不痛 提交于 2020-01-17 07:30:13
问题 this is my method def add @result @log = Log.new(params[:log]) if @log.save result = "success"; else result = "fail"; end render :json => result end and this is my routes.rb match "/logs/add/:value/:category/:note/:own" => "logs#add" when i try putting this URL: http://localhost:3000/logs/add/338/testcat/testnote/testown and it returns the json correctly and new item was added to the database but all of the fields(value,category,note,own) are null. please help :( I've already solved the above

How to sum a grouped column in AREL

喜夏-厌秋 提交于 2020-01-17 05:58:45
问题 in Rails 3/AREL Model.group(:label).sum(:value) will do SELECT sum(value), label from model_table group by label I am trying to find the AREL way of doing SELECT sum(value) from (select value, label from model_table group by label) which is Model.group(:label).map(&:value).sum using ruby to sum, how do I do this in SQL/AREL 回答1: Not sure this makes sense. Your core SQL is not valid: SELECT value, label FROM model_table GROUP BY label You cannot have a GROUP BY without an aggregation function

Nested form and has_many :through

丶灬走出姿态 提交于 2020-01-17 05:50:11
问题 I have a little sample app where there are 3 models: Members, Groups and Subscriptions. The idea is that member can subscribe to groups. class Member < ActiveRecord::Base has_many :subscriptions, dependent: :delete_all has_many :groups, through: :subscriptions attr_accessible :email validates :email, presence: true end class Group < ActiveRecord::Base has_many :subscriptions, dependent: :delete_all has_many :members, through: :subscriptions accepts_nested_attributes_for :subscriptions attr

Rails 3: Routing error only in a certain method

╄→尐↘猪︶ㄣ 提交于 2020-01-17 05:17:28
问题 I am experiencing a strange behavior for a certain record in my routes.rb. Here is an excerpt of my routes.rb: resources :stores do resources :stores_spare_parts do collection do post :update_attribute_on_the_spot end end end When I now call the method url_for in my index action of the stores_spare_parts Controller, it returns http://127.0.0.1:3000/stores/1/stores_spare_parts/update_attribute_on_the_spot . But when I do the same in my create action it stops working with the following error:

Active Record Rails 3 associations not working properly

徘徊边缘 提交于 2020-01-17 03:45:14
问题 I have the following classes with associations: class Customer < ActiveRecord::Base has_many :orders has_many :tickets, :through => :orders has_many :technicians, :through => :ticket has_many :services, :through => :ticket end class Order < ActiveRecord::Base belongs_to :customer has_many :tickets has_many :technicians, :through => :tickets has_many :services, :through => :tickets end class Service < ActiveRecord::Base has_many :tickets has_many :technicians, :through => :tickets has_many

When I try the command rails server on a new project I get this error

只愿长相守 提交于 2020-01-17 03:38:08
问题 I am running Debian 7. I am using RVM. I am also running mySQL. I am new to ruby in general as well as rails. Please excuse any of me if I seem naive at all. I setup a project with: rails new projectname -d mysql Then I went into that directory and ran: rails server I then get this error: /home/user/.rvm/gems/ruby-2.0.0-p247/gems/execjs-2.0.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available

Filter model with multiple has many through

三世轮回 提交于 2020-01-17 02:23:28
问题 Given Document: has_many :shares has_many :groups, :through => :shares User: has_many :memberships has_many :groups, :through => :memberships Group: has_many :memberships has_many :users, :through => :memberships has_many :shares has_many :documents, :through => :shares I need to show only documents for a given instance of User, current_user. @documents = current_user.groups.documents doesn't cut it. How can i filter down to only the documents that have at least on group in common with the

Rails - using group_by and has_many :through and trying to access join table attributes

笑着哭i 提交于 2020-01-17 02:23:04
问题 For some background, please see my question: Rails app using STI -- easiest way to pull these records? I have some models joined with a has_many through relationship using a third join table (Recipe and Ingredient joined through RecItem). So the guys on the prior question helped me to group my recipe's ingredients by type - this is exactly what I wanted. However, now that I am accessing @recipe.ingredients instead of @recipe.rec_items, I can't get back to the data stored in the rec_items join

Rails - using group_by and has_many :through and trying to access join table attributes

血红的双手。 提交于 2020-01-17 02:23:02
问题 For some background, please see my question: Rails app using STI -- easiest way to pull these records? I have some models joined with a has_many through relationship using a third join table (Recipe and Ingredient joined through RecItem). So the guys on the prior question helped me to group my recipe's ingredients by type - this is exactly what I wanted. However, now that I am accessing @recipe.ingredients instead of @recipe.rec_items, I can't get back to the data stored in the rec_items join