[Rails] Re: "Best practice" for accessing session from model

2009-12-20 Thread Lin Wj
Thanks

totally got lost ploughing thru Userstamp's code
probably a good time for me to start learning some metaprogramming
-- 
Posted via http://www.ruby-forum.com/.

--

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-t...@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] "Best practice" for accessing session from model

2009-12-20 Thread Lin Wj
i need to do update pm a "updated_by" field with a session variable
"user" on a model after_save.

but accessing session variables from models is supposedly bad

whats the usual best practice for this kinda scenario ?
-- 
Posted via http://www.ruby-forum.com/.

--

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-t...@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] logging in using current Windows user information

2009-08-31 Thread Lin Wj

is it possible to fetch the current logged in window user information
for authentication / log in purposes ?
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
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] Help with Code Tweaking

2009-04-03 Thread Lin Wj

scenario : select distinct years from members and their respective
record count of that particular year.

eg:  [{year = 2008 , count = 45123},{year = 2007 , count = 12332} ]

previously , i was using "select distinct tochar(datetime)" , it ended
up taking quite a while to fetch the records so i switched to this code.


relationship group 1 : N members

rootgroup is a pretched group


member = root_group.members.find(:all,
  :select => "max(datetime) as maxdate,min(datetime) as mindate"
)[0]

return member.mindate.year.upto(member.maxdate.year).inject({}) do
|year|

  #return hash with year and member count for that year

  compare_date = Date.new(year,1,1)

  {year , root_group.members.find(
   :conditions => [ "datetime >= ? AND datetime < ?",
 compare_date,
 compare_date + 1.year ],
:select => 'count(*)')}
   end


any ideas on how to tweak it ?

it really looks quite clumsy at the moment
and iam repeating the code for drilling into the months and days ,
it really feels like bad practice.


thanks
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
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] how to use Wsdl2ruby generated files

2009-03-02 Thread Lin Wj

i am cloning a current soap server to ruby
and i have zero experience in this soap thing.

i did a wsdl2ruby on the url and generated 3 riles

DriverDataServiceMappingRegistry.rb
DriverDataService.rb
DriverServiceServant.rb


how do i use the files to setup a soap server ?
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
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] Re: ActiveWebService returning custom types

2009-03-02 Thread Lin Wj

nevermind the above posts
i wasnt paying attention


i created a model Sample

changed code to

class TestApi < ActionWebService::API::Base
   api_method :get_me, :returns => [Sample]
end

class MarketdataController < ApplicationController
   ...
  def poll
Sample.find(:all,:limit =>1)
  end


here i get all sorts of mapping errors

#1
returns => [Sample]#it should expect a Sample object

i return a Sample.find(:all,:limit=>1)[0]
and i get a "Cannot map Sample to SOAP/OM"

i return a Sample.find(:all,:limit=>1) #which would return an array 
containing Sample objects , it errors out and says
"Don't know how to cast Array to Sample"
thats expected

then i tried this
#2
returns => [[Sample]] #it should expect an array of sample objects ?
i return a sample.find(:all,:limit=>1)
and i get a "Cannot map Array to SOAP/OM"


Any ideas on how to get it to cast properly ?







-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
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] Re: ActiveWebService returning custom types

2009-03-01 Thread Lin Wj

disregard this section
 #[get_indices(),get_stocks(),get_summary(),DateTime.now.to_s]
 indices = get_indices()
 stocks = get_stocks()
 summary = get_summary()
 current_time = DateTime.now
 tempsnapshot = Snapshot.new(indices,stocks,summary,current_time)
 tempsnapshot


-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
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] ActiveWebService returning custom types

2009-03-01 Thread Lin Wj

class Sampleclass
 attr_reader :temp_arr,:temp_hash,:temp_str
  def initialize(temp_arr,temp_hash,temp_str)
@temp_arr=temp_arr
@temp_hash=temp_hash
@temp_str=temp_str
  end

class TestApi < ActionWebService::API::Base
   api_method :get_me, :returns => [Sampleclass]
end

class TestController < ApplicationController
  wsdl_service_name 'Test'
  web_service_api TestApi
  web_service_scaffold :invocation if Rails.env == 'development'

  def get_me
#[get_indices(),get_stocks(),get_summary(),DateTime.now.to_s]
indices = get_indices()
stocks = get_stocks()
summary = get_summary()
current_time = DateTime.now
tempsnapshot = Snapshot.new(indices,stocks,summary,current_time)
tempsnapshot
[Sampleclass.new(['1','2',3'],
 {'a' => '1',
  'b' => '2' },
 'something' ) ]
  end
end


i got this error
Don't know how to cast Sampleclass to Sampleclass

how do i define custom classes as return paramters
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
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] Actionwebservice for rails2.2.2 / ruby 1.8.7

2009-02-27 Thread Lin Wj

has anyone gotten action actionwebservice to work for this config ?

tried instructions from
http://www.texperts.com/2007/12/21/using-action-web-service-with-rails-20/

and got a "activate': can't activate actionpack"   on server startup
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
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] strict XHTML compliant ajax library

2009-02-26 Thread Lin Wj

problem : i have to develope a app using ajax features and it has to run
in an environment(web tv related) which is very strict about XHTML
compliance.

and ajax codes generated by rails doesnt seem to be compliant.
(they work on normal webpages , but not in the webtv env)

other than writing my own ajax codes and including them as helpers.

is there any other way ?



thanks
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
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] setting header in views?

2009-01-13 Thread Lin Wj

currently iam using FasterCSV to render csv pages

format.csv do
csv_string = FasterCSV.generate do |csv|
  # header row
  csv << @query_result[0].keys

  @query_result.each do |x|
csv << x.values
  end
end
#send it to the browser
send_data csv_string,
  :type => 'text/csv; charset=iso-8859-1; header=present',
  :disposition => "attachment; filename=#{'data'}.csv"
  end

i wanted to contain the "display codes" inside a view so i tried using
respond_to do |format|
   format.csv
and having a matching show.csv.erb

but i cant set the header information
-> send_data csv_string,
  :type => 'text/csv; charset=iso-8859-1; header=present',
  :disposition => "attachment; filename=#{'data'}.csv"
inside the view itself

anyway to do it ?
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---