ruby-on-rails-3.2

Rails 3.2 - Nested Resource Passing ID

霸气de小男生 提交于 2019-12-12 02:52:07
问题 Okay so my associations are: Outlet -> has_many :monitorings Monitoring -> belongs_to :outlet My Routes: resources :outlets do resources :monitorings end View: <%= link_to new_outlet_monitoring_path(@outlet) %> When I click the link, the logs show that the outlet_id is passed as a parameter to the new page correctly. But when saving the monitoring record, the outlet_id becomes nil. Any help? UPDATE: # views/monitorings/_form.html.erb <%= form_for(@monitoring) do |f| %> <h2>Type of Monitoring<

Rails query by record association

余生长醉 提交于 2019-12-12 02:42:42
问题 I'm relatively new to Rails and to learn more am trying to build a simple blog. One of the issues I'm running in to is tagging. I have a Tag model that I am using to create and manage tags that can be applied to posts. I also have a Post model. I need to be able to associate any of the tags with the post, retrieve them for output, and be able to filter/query posts by a specific tag. So far I've created a column on Post called tags , which gets assigned an array of Tag IDs, and is then

My development environment was wiped out and I'm getting a series of errors in trying to fix it

大憨熊 提交于 2019-12-12 02:31:42
问题 So I was messing with gemsets with a friend of mine and I accidentally deleted a one. I wasn't sure what happened, so I just kinda brushed it off. Then I went to run 'rails server' for my old app that I've been working on and nothing happens for like 2 minutes and then finally it spits out an error. /Users/Nick/.rvm/bin/ruby: line 6: /Users/Nick/.rvm/bin/ruby: Argument list too long /Users/Nick/.rvm/bin/ruby: line 6: /Users/Nick/.rvm/bin/ruby: Undefined error: 0 So then I did everything

Rails devise not working for rails 3.2.1 on localhost

橙三吉。 提交于 2019-12-12 01:29:12
问题 I followed each and every single step for devise to work on my localhost as discussed under this tutorial - http://www.slideshare.net/wleeper/devise-and-rails upto page 8 of 22 and I was expecting the same user login form as mentioned on the page 8 but apart from this, i am getting this error- If i keep the comments as it is on routes.rb file, # match ':controller(/:action(/:id))(.:format)' then this message flags - And when i uncomment this line it show this error- Have very less idea about

Autocompleted search form is not working in all pages

孤街醉人 提交于 2019-12-12 01:16:10
问题 When I use autocompleted search form in some pages it is working but for when I click the "Home", "Help" or "Users" links on navbar, I can only use search form without autocompleted feature. layouts/header.html.erb <% if logged_in? %> <%= form_tag users_path, class: "navbar-form navbar-left", method: :get do %> <% if params[:query].present? %> <%= link_to "clear", users_path%> <%end%> <div class="input-group input-group-md"> <%= text_field_tag :query, params[:query], class: "form-control",id:

How to validate that payment can never cause invoice amount payable to be less than zero?

有些话、适合烂在心里 提交于 2019-12-12 01:04:26
问题 I have this class: class Payment < ActiveRecord::Base attr_accessible :amount, :invoice_id belongs_to :invoice validates :amount, :numericality => { :greater_than => 0, :less_than_or_equal_to => :maximum_amount } after_save :update_amount_payable after_destroy :update_amount_payable private def maximum_amount invoice.amount_payable end def update_amount_payable invoice.update_amount_payable end end class Invoice < ActiveRecord::Base has_many :payments after_save :update_amount_payable def

How to make text fields for nested_attributes in rails for selected records?

我与影子孤独终老i 提交于 2019-12-12 00:34:44
问题 I have a three models Report , Question , Answer Answer belong_to :question Question belong_to :reports has_many :answers, :dependent => :destroy accepts_nested_attributes_for :answers, :allow_destroy => true Reports has_many :questions, :dependent => :destroy accepts_nested_attributes_for :questions, :allow_destroy => true While creating a new report some questions are randomly picked to be added to the report and show form in this way : Report Form <%= form_for @report do |f| %> <div class=

simple Ruby Input and Output Exercise log [duplicate]

自古美人都是妖i 提交于 2019-12-11 23:42:08
问题 This question already has an answer here : How do I create this File Input and Output assignment in Ruby (1 answer) Closed 6 years ago . I have a project in my programming class. This is my assignment: Create a program that allows the user to input how many hours they exercised for today. Then the program should output the total of how many hours they have exercised for all time. To allow the program to persist beyond the first run the total exercise time will need to be written and retrieved

How do I bypass validation rules set for a nested attribute in ruby on rails?

ぃ、小莉子 提交于 2019-12-11 23:25:10
问题 I have a micropost form which allows a user to upload a photo and type some content to go with it. The image file field is the nested attribute from my photo model. It has a validation rule "presence => true". This is not required for microposts. User are allowed to post microposts without images/photos. How ever I use the same photo model for the users image gallery and a photo is required at the time of form submission so I can't disable this rule. Is there any way to bypass the validation

Nested Attributes in ruby on rails

社会主义新天地 提交于 2019-12-11 21:58:05
问题 i want to create comments in ruby but i have problem 1) posts_controller.rb def comment Post.find(params[:id]).comments.create(params[:comment]) flash[:notice] = "Added your comment" redirect_to :action => "show", :id => params[:id] end 2)show.html.erb <%= form_tag :action => "comment", :id => @post %> <%= text_area "comment", "message" %><br /> <%= submit_tag "Comment" %> </form> 3)post.rb class Post include Mongoid::Document include Mongoid::Timestamps::Created include Mongoid::Timestamps: