[Rails] how to save one value into the attributes of all rows in a model
When i use Model.all and i want to save this one value into all the rows of the model how do i do it without using a "for" loop. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Getting the top results only by group in a .find statement
This is my table model name is bids id | bid | keyword 1 | 2 | orange 2 | 3 | orange 3 | 1 | red 4 | 3 | blue 5 | 6 | red what i want is the get these the top bidder of each unique keyword in one .find statement --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] /lib daemon folder: how do i add a module into the daemon?
I am using the daemons plugin. I have just one problem how do i add modules from the /lib folder to the /lib/daemons/daemon.rb file eg. /lib/basic_functions.rb this is the file i want to load in daemon.rb contents daemon.rb: #!/usr/bin/env ruby # You might want to change this ENV["RAILS_ENV"] ||= "production" require File.dirname(__FILE__) + "/../../config/environment" #require File.dirname(__FILE__) + "/../../lib/basic_functions.rb"(this didn't work) #require '../basic_functions.rb' (this didn't work) $running = true Signal.trap("TERM") do $running = false end while($running) do # Replace this with your code get_current_time ActiveRecord::Base.logger.info "This daemons is still running at # {...@current_time}.\n" sleep 5 end contents of basic_functions module BasicFunctions def get_current_time #...@current_time = Time.now.beginning_of_month + 27.days #...@current_time = Time.now.beginning_of_month + 13.days @current_time = Time.now end def get_time_period get_current_time @absmid = @current_time.beginning_of_month + 14.days @midperiod = @absmid - 2.days if @current_time >= @absmid @begin_bid_time = @absmid @end_bid_time = @current_time.next_month.beginning_of_month - 2.days @ad_window_begin = @current_time.next_month.beginning_of_month @ad_window_end = @current_time.next_month.beginning_of_month + 15.days else @begin_bid_time = @current_time.beginning_of_month @end_bid_time = @midperiod @ad_window_begin = @absmid @ad_window_end = @current_time.next_month.beginning_of_month end end end --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] SMTP settings for action mailer
with rails 2.2.2 action mailer requires a valid ssl certificate i have a question about routing my smtp settings for my postfix are now ActionMailer::Base.smtp_settings = { :address => "smtp.mydomain.com", :port => 25, :domain => "mydomain.com", :authentication => :plain, :user_name => "mydomain_mai...@mydomain.com", :password => "password" } both the email server and the rails app are on the same machine if i don't have the address as 127.0.0.1 is it routing information through the internet instead of internally in the machine? if i use 127.0.0.1 i will get the ssl error because the host does not match up. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Actionmailer and postfix settings
Hi, I am having problems configuring my actionmailer to work with postfix. I followed this tutorial: http://howtoforge.org/virtual-users-and-domains-postfix-courier-mysql-centos5.1 and i got the server set up. at first i fixed the mail settings to work with gmail using this tutorial: http://www.danielfischer.com/2008/01/09/how-to-use-gmail-as-your-mail-server-for-rails/ and my app worked with gmail. but now i want it to work with my newly built email server. I read somewhere if your server has tls u have to do something special with actionmailer for it to work so i am relying on fischer's workaround. so i inputed this into the mailer.yml file that danielfischer created: :address: localhost :port: 25 :domain: localhost :user_name: mai...@mydomain.com :password: secret :authentication: :plain :tls: true Should i have used mydomain instead of localhost? I just can't seem to get it to connect there is nothing in my tail - f /var/log/maillog error Please help! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] serializing active record objects do not save after first slice
Hi, i am having a very weird problem i have an array Model: serialize :marketarray Controller @marketobject = Market.find(1) @marketobject.marketarray = ["red","blue","green"] I do this @marketobject.marketarray.slice!(0) @marketobject.save! but it does not change the Market.marketarray to ["blue","green"] it just keeps the original array as if it did not happen if i do this @marketobject.marketarray = ["1","1"] @marketobject.save! then it saves the marketarray to ["1","1"] please help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] select_tag and select_date how to change inline font
I have been trying to change the font size in the select_date but i haven't had any luck here's what i did: <%= select_date( Date.today, :prefix => 'prom_date_end', :order => [ :day,:month, :year], :html => {:style => "font-size: xx-small;"}) %> --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Validation errrors: how to get rid of "Validation failed: " and the Objects in them
Hi when ever i do rescue Exception => e flash[:error] = e.message the e.message will always contain the "Validation error:" string and the Object Example: Validation failed: Price "message:", Price "message" How do i tell rails that I just want the message? and not the other parts of the validation error to be displayed? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Active record :find having an if statement inside the conditions
Hi, i was just wondering if its is possible to put a if statment inside the find conditions for example: grovery_price = model.find(:first, :conditions => [ "if x = ? then y must = ?", 200, 300] I have been googling for some time for a solution to this but i just can't seem to find any. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Find active record condition of not equal
Hi, I have tried creating a not equal condition in the find statment but it just outputs an empty array. model.find(:first, :conditions => [" id = ? AND market = ? AND promotion <> ? " , id , name, "y"],:order => 'id desc').price I have tried != instead of <> I have tried googling for the answer but i can't seem to find it. What do i need to put to give a not equal condition? Database is mysql. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Ajax on failure message
How do i change the ajax failure message <% remote_form_for(:comment, :url => grocery_comments_path(params [:id]), :html => { :id => 'new_comment_form' }, :method => :post, :update => { :failure => "error" }) do |form| %> the :update => { :failure => "error" } gives me the usual error messages inside the How do i change this error message to a string? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: form.text_area, how do you empty its contents?
Never mind i got it @comment.body = "" before the page.replace On Nov 1, 1:34 am, tyliong <[EMAIL PROTECTED]> wrote: > Hi, after i click submit and refresh the parital(with > page.replace_html) with the remote_form_for, the <%= > form.text_area :body, :rows => 10, :cols => 40 %> still contains the > previous text. how do i totally remove the text inside of it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] form.text_area, how do you empty its contents?
Hi, after i click submit and refresh the parital(with page.replace_html) with the remote_form_for, the <%= form.text_area :body, :rows => 10, :cols => 40 %> still contains the previous text. how do i totally remove the text inside of it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Passing a function with arguments to another function with arguments that is a loop
Hi, I am a noobie. I just want to know what is the standard or most effective way of doing this I have two functions def display_price(grocery,batch) grocery_price = grocery.send(batch).price if grocery_price number_to_currency(grocery_price) else "NA" end end def loop(func,matrix) matrix.each { |matrix| display_price(@grocery,matrix) } end the "func argument" in the loop function is suppose to be display_price but how do i put it in if the "batch" is the thing that I want to be looped through? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: protect_from_forgery :only => [:create, :delete, :update] what does this do exactly?
how do i find what ajax method is being used?. could you possibly give an example? On Aug 29, 5:01 am, hitch <[EMAIL PROTECTED]> wrote: > The protect_from_forgery is on by default to prevent Cross Site > Request Forgery attacks. > > You don't normally have to add this to your controller. What you are > actually doing in this case is adding the call so that your ajax > method is NOT protected from attacks. > It might make more sense to use the following: > > protect_from_forgery :except => :your_ajax_method > > The end result should be the same. > And listing which methods should not have protection is probably a > more robust solution, since forgetting to add to the :except list will > generate the kind of error you are seeing. Forgetting to add methods > to the :only list will not generate any error messages. > > If you do not want to exclude your ajax method, your ajax submission > needs to include the token. This is done automatically by the > framework for most forms. > > On Aug 28, 8:46 am, "Tan YL" <[EMAIL PROTECTED]> wrote: > > > How come I have to add it in my controller to get rid of token error? > > > -Original Message- > > From: rubyonrails-talk@googlegroups.com > > > [mailto:[EMAIL PROTECTED] On Behalf Of Jorg Lueke > > Sent: Thursday, August 28, 2008 9:46 PM > > To: Ruby on Rails: Talk > > Subject: [Rails] Re: protect_from_forgery :only => [:create, :delete, > > :update] what does this do exactly? > > > It's the default in any rails 2.0 project. > > > On Aug 27, 9:54 am, "Tan YL" <[EMAIL PROTECTED]> wrote: > > > In production mode it's a default? Sorry still haven't got my app out of > > > development mode so I have no idea what happens during production. > > > > -Original Message- > > > From: rubyonrails-talk@googlegroups.com > > > > [mailto:[EMAIL PROTECTED] On Behalf Of Jorg Lueke > > > Sent: Wednesday, August 27, 2008 10:18 PM > > > To: Ruby on Rails: Talk > > > Subject: [Rails] Re: protect_from_forgery :only => [:create, :delete, > > > :update] what does this do exactly? > > > > (3)If it is that good should i use it in every controller?. Somebody > > > must thinkk so because it is the default in every app built. > > > > On Aug 27, 9:12 am, tyliong <[EMAIL PROTECTED]> wrote: > > > > protect_from_forgery :only => [:create, :delete, :update] > > > > > Questions: > > > > > (1)why do i need to put it in when i get an authenticate token error > > > > from passing an :id from the controller through AJAX? > > > > (2)are there any disadvantages in doing this(does this expose security > > > > loopholes)? > > > > (3)If it is that good should i use it in every controller? > > > > > from ruby api( i still don't understand what this means): > > > > Protecting controller actions from CSRF attacks by ensuring that all > > > > forms are coming from the current web application, not a forged link > > > > from another site, is done by embedding a token based on the session > > > > (which an attacker wouldn't know) in all forms and Ajax requests > > > > generated by Rails and then verifying the authenticity of that token > > > > in the controller. Only HTML/JavaScript requests are checked, so this > > > > will not protect your XML API (presumably you'll have a different > > > > authentication scheme there anyway). Also, GET requests are not > > > > protected as these should be indempotent anyway. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Need help with AJAX partial not refreshing browser asking to save .js instead
never mind i solved it On Sep 23, 4:46 pm, tyliong <[EMAIL PROTECTED]> wrote: > Hi, when i use the updatepassword action, it does not refresh the ajax > partial but forces the browser to save a file > why does that happen? > > def updatepassword > @user = current_user > return unless request.post? > if User.authenticate(current_user.login, params[:old_password]) > if ((params[:password] == params[:password_confirmation]) && ! > params[:password_confirmation].blank?) > current_user.password_confirmation = > params[:password_confirmation] > current_user.password = params[:password] > if current_user.save > flash[:notice] = "Password successfully updated." > redirect_to login_path #profile_url(current_user.login) > else > flash[:error] = "An error occured, your > password was > not changed." > respond_to do |format| > format.js > end > end > else > flash[:error] = "New password does not match the > password confirmation." > @old_password = params[:old_password] > respond_to do |format| > format.js > end > end > else > flash[:error] = "Your old password is incorrect." > respond_to do |format| > format.js > end > end > end --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Need help with AJAX partial not refreshing browser asking to save .js instead
Hi, when i use the updatepassword action, it does not refresh the ajax partial but forces the browser to save a file why does that happen? def updatepassword @user = current_user return unless request.post? if User.authenticate(current_user.login, params[:old_password]) if ((params[:password] == params[:password_confirmation]) && ! params[:password_confirmation].blank?) current_user.password_confirmation = params[:password_confirmation] current_user.password = params[:password] if current_user.save flash[:notice] = "Password successfully updated." redirect_to login_path #profile_url(current_user.login) else flash[:error] = "An error occured, your password was not changed." respond_to do |format| format.js end end else flash[:error] = "New password does not match the password confirmation." @old_password = params[:old_password] respond_to do |format| format.js end end else flash[:error] = "Your old password is incorrect." respond_to do |format| format.js end end end --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Seriously stumped cannot call attribute out
this is what it says in console >> Groceries.find(1).supermarket.p >> ArgumentError: wrong number of arguments (0 for 1) from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/ active_record/associations/association_proxy.rb:177:in `p' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/ active_record/associations/association_proxy.rb:177:in `send' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/ active_record/associations/association_proxy.rb:177:in `method_missing' from (irb):30 On Sep 7, 11:14 pm, tyliong <[EMAIL PROTECTED]> wrote: > Hi, i am having problems displaying a simple attribute. what is weird > is that all the other attributes are can be called but not .p . I > have been racking my brain on why but I just don't get it. it doesn't > make sense i can call nearly every attribute except this one > > DB creation code: > > create_table :supermarket do |t| > t.integer :groceries_id > t.decimal :price, :precision => 8, :scale => 2 > t.integer :p > t.decimal :numindeal, :precision => 8, :scale => 2 > t.decimal :promprice, :precision => 8, :scale => 2 > t.timestamps > end > > Table > > id |groceries_id |price|p|numindeal|promprice| > 1 |1| |3.00|1|3.00 ||3.00 | > > Helper.rb > > def pricecheck(groceries,supermarket) > z = groceries.send(supermarket) > > z.groceries_id > z.price > z.numindeal > z.promprice {all these work} > z.p {this gives "wrong number of arguments (0 for 1)"} > end > > view code: > > <%= pricecheck(groceries,"supermarket") %> --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Seriously stumped cannot call attribute out
Hi, i am having problems displaying a simple attribute. what is weird is that all the other attributes are can be called but not .p . I have been racking my brain on why but I just don't get it. it doesn't make sense i can call nearly every attribute except this one DB creation code: create_table :supermarket do |t| t.integer :groceries_id t.decimal :price, :precision => 8, :scale => 2 t.integer :p t.decimal :numindeal, :precision => 8, :scale => 2 t.decimal :promprice, :precision => 8, :scale => 2 t.timestamps end Table id |groceries_id |price|p|numindeal|promprice| 1 |1| |3.00|1|3.00||3.00 | Helper.rb def pricecheck(groceries,supermarket) z = groceries.send(supermarket) z.groceries_id z.price z.numindeal z.promprice {all these work} z.p {this gives "wrong number of arguments (0 for 1)"} end view code: <%= pricecheck(groceries,"supermarket") %> --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: nested array .select statment
ok i managed to get this out smallest = x.min{|x,y| x[0] <=> y[0]}[0] result = x.select{|g| g[0] == smallest}.map{|g|g[1]} and it works but the problem is when i apply it to my app because [[1,"h"],[2,"g"]] is actually [[groceries.price,"h"]] and it gives undefined method `[]' for # meaning that theres something wrong with groceries.price but in the migration file .price is specified to be t.decimal :price, :precision => 8, :scale => 2 I don't understand why rails is giving an undefined method when i subsitute in decimals for 1 and 2 in the array it is ok. On Sep 6, 8:00 pm, tyliong <[EMAIL PROTECTED]> wrote: > Hi! > > the array is like this > [[1,"h"],[2,"g"]] > i want to select the parts of the array with the minimum value > and show the 2nd part of the element only meaning the strings like "h" > and "g" > > i've tried this but it doesn't work > x.select{|c| c.first = [x.min{|a,b| a.first <=> b}.first]}.last > > and i get comparison of Array with Array failed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] nested array .select statment
Hi! the array is like this [[1,"h"],[2,"g"]] i want to select the parts of the array with the minimum value and show the 2nd part of the element only meaning the strings like "h" and "g" i've tried this but it doesn't work x.select{|c| c.first = [x.min{|a,b| a.first <=> b}.first]}.last and i get comparison of Array with Array failed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: nested array minimum
solved On Sep 6, 4:16 pm, tyliong <[EMAIL PROTECTED]> wrote: > Hi, > > usually when i do this: > > x = [1,2,3,] > > result = x.min > > but let's say I have a nested array > > x = [ [1,"h"], [2,"c"]] > > how to i just display the min value (1) and its pair value "h" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] nested array minimum
Hi, usually when i do this: x = [1,2,3,] result = x.min but let's say I have a nested array x = [ [1,"h"], [2,"c"]] how to i just display the min value (1) and its pair value "h" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---