[Rails] Re: require_role on a per action basis
Consider restful_authentication and rolerequirement http://code.google.com/p/rolerequirement/ On May 26, 4:01 pm, Mike Buckley wrote: > I am working on an app that has three roles (user, admin, business). I > have the situation where all three roles interact with the same > controller, but have access to different actions. Some actions are > authorized for 2 roles (admin, business), and others are only authorized > for one role (administrator). > > Does anyone know if there is a commonly used pattern for security on a > per action basis? > > What I would like to do is be able to map which roles are authorized to > call which actions and be able to call a :before_filter in my > controller. > > In my head I'm thinking of something like > > before_filter :authorize_action => :except [:public_action1, > :public_action2] > > Thanks for any input. > -- > Posted viahttp://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] IIS, Net::HTTP::Get, and Basic Authentication
I'm getting a 401.2 from IIS You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept. The sysadmin says that basic auth is enabled. Is there something special about how rails handles basic auth? Is there a way for me to see what the server actually gets and what the headers say is acceptable? My Code: def get_wsdl(url=nil) return false if url.nil? url = URI.parse(url) unless url.is_a?(URI) connection = Net::HTTP.new(url.host, url.port) connection.use_ssl = true connection.verify_mode = OpenSSL::SSL::VERIFY_NONE connection.start do |http| req = Net::HTTP::Get.new("#{url.path}?#{url.query}") req.basic_auth 'username','password' puts http.request(req).body 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] Re: Active Resource custom method using POST
I may just go to the command line with curl - that seems to work without a hitch. Also, for anyone looking at creating a POST body, the code I posted previously for converting a hash to POST body can be completely replaced with {hash}.to_param. In my case: body = input.to_param Good luck - On May 26, 9:28 am, BenH wrote: > I've written a small piece of code that is supposed to place an order > in a order handling system. get, put and delete functions are working > great but I cannot get post to function at all... the error I get back > from the code below is 400 (bad request). I think it has something to > do with the headers but I don't know how to get more info out of this. > Is there a problem with the way I am handling the post method? > > Thank you for your input!! > Ben > > ### > > class User < ActiveResource::Base > self.site = "http://www.a_restful_api.com/api/"; > self.element_name = "user" > self.format = :json > > def place_order(input) > # ... handle input constraints. input is a hash > > # parse the hash to end up with "key=value&key=value&key=value" > body = "" > input.keys.sort.each do |k| > if k == input.keys.sort.first > body += %Q{#{k}=#{input[k]}} > else > body += %Q{&#{k}=#{input[k]}} > end > end > > user = User.find_by_remote_id(self.user_id) > header ||= make_header(user) # this function returns a hash with > the various elements in the header > > method_string = "#{self.class.prefix}#{self.class.collection_name}/ > #{self.user_id}/store/orders" > resp = connection.post(method_string,body,header) > 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] Re: String Manipulation
Try this: words = "Kid games need to be both fun and educational. Aimed at ages pre-K through middle school, safe environment to discover their abilities and learn new skills with interactive and fun computer games. Our games build skills in math, logic, memory, vocabulary, alphabet, spelling, geography, computer skills, color identification, shape identification and other various problem solving. Our commitment to parents, teachers, and kids, is to connect earning and skill building with a sense of challenge, fun, and self esteem." line_length = 10 word_arry = words.split(" ") text = (0..(words.length / line_length)).inject([]) {|v,num| start = num * line_length; v << %Q{<= #{words[(start)...(start + line_length)].join(" ")} =>}} text.join("\n") Shame on me... On May 26, 3:45 pm, Marnen Laibow-Koser wrote: > Ruby One wrote: > > [...] > > > > > I am newbee so do not much syntax and loops can you please help me i > > that. > > > thanks > > Check out the "pickaxe book" (Programming Ruby, available on the Web). > Pay particular attention to regular expressions, the String class > (especially the split and join methods), the Array class, and looping > constructs such as each. Then try writing your function. If something > goes wrong that you can't figure out, tell us what you tried, and what > errors or other output you got. > > Good luck! > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...@marnen.org > -- > Posted viahttp://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: I need support it is urgent
filemodel.extension = File.extname("/some/path/myfile.xls") # output is ".xls" Do you mean instead that you would like to store an xls file? If so check out acts_as_attachment, attachment_fu or file_column plugins. Ben On May 26, 3:39 am, railsrao wrote: > Hi every one > I need help , i have a application ofhttp://www.projectlaika.org/ > i need to store a xls file extension please provide how to do make a > list of steps if possible and i hope to get reply as soon as possible. > Thanks > team --~--~-~--~~~---~--~~ 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: String Manipulation
Is the point of your post to display the text at fixed line widths? On May 26, 2:01 pm, Ruby One wrote: > Hi all, > > Help needed urgently > > Example: this could be the string. > > Kid games need to be both fun and educational. Aimed at ages pre-K > through middle school, safe environment to discover their abilities and > learn new skills with interactive and fun computer games. Our games > build skills in math, logic, memory, vocabulary, alphabet, spelling, > geography, computer skills, color identification, shape identification > and other various problem solving. Our commitment to parents, teachers, > and kids, is to connect learning and skill building with a sense of > challenge, fun, and self esteem. > > Output > Kid games need to be both fun and educational. Aimed at ages pre-K > through => > <= middle school, safe environment to discover their abilities and learn > new => > <= skills with interactive and fun computer games. Our games build > skills in => > . > . > => a sense of challenge, fun, and self esteem. > > Regards and thanks > -- > Posted viahttp://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: ruby and MySql
Does the database exist that you are connecting to? #> mysqladmin create temp_development also ensure you have the mysql gem installed (current versions of rails require the native gem) #> sudo gem install mysql lastly make sure your project can communicate with the database rake db:migrate If all is well the only thing you should have to do in the future is ensure the database exists with the mysqladmin command. On May 26, 2:04 pm, William Downs wrote: > Hi there - new to RoR but very excited about it indeed - > > I have just manged to install everything. > > However, when I browse tohttp://localhost:3000/then click the "About > your application’s environment" - from the console I get : > > Status: 500 Internal Server Error > no such file to load -- mysql > > Perhaps someone can tell from my configuration what is wrong ??? What I > may be missing ?? > > My configuration is > > * Mac OSX 10.4.11 > * Ruby - v 1.8.6 > * Rails > * Mongrel > * RubyGems 1.3.3 > * MYSQL 5.0.27 > > database.yml file = > > development: > adapter: mysql > encoding: utf8 > database: temp_development > username: root > password: > socket: /tmp/mysql.sock > > # Warning: The database defined as 'test' will be erased and > # re-generated from your development database when you run 'rake'. > # Do not set this db to the same as development or production. > test: > adapter: mysql > encoding: utf8 > database: temp_test > username: root > password: > socket: /tmp/mysql.sock > > production: > adapter: mysql > encoding: utf8 > database: temp_production > username: root > password: > socket: /tmp/mysql.sock > > Many thanks in advance > > Glorifindal > -- > Posted viahttp://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: library for URL parameters adding, removing, or replacing?
URL paramaters are usually passed as a hash, with that if a new key matches and existing key the new key/value pair will overwrite the existing key/value pair thus preventing duplicate entries. Ben On May 26, 11:47 am, Jian Lin wrote: > i think PHP doesn't have such simple functions yet... does Ruby have > it? > > if in PHP, when we add a param to the URL > > $redirectURL = $printPageURL . "?mode=1"; > > it works if $printPageURL is "http://www.somesite.com/print.php";, but if > $printPageURL is changed in the global file to > "http://www.somesite.com/print.php?newUser=1";, then the URL becomes > badly formed. If the project has 300 files and there are 30 files that > append param this way, we need to change all 30 files. > > the same if we append using "&mode=1" and $printPageURL changes from > "http://www.somesite.com/print.php?new=1"; to > "http://www.somesite.com/print.php";, then the URL is also badly formed. > > is there a library in Ruby/Rails that will automatically handle the "?" > and "&", and even checks that existing param exists already and removed > that one because it will be replaced by the later one and it is not good > if the URL keeps on growing longer? > -- > Posted viahttp://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: memcache for variables
Except in the collection you actually would put [u.name,u.id] On May 26, 11:33 am, BenH wrote: > in your config/environment/development.rb file (or whatever > environement your are configuring) > > config.cache_store = :mem_cache_store > > Depending on how much memory you want to consume you can either load > your whole user model, the name to ID collection or just the users > that log in. > > In the User model do something like: > > def self.names > Rails.cache.fetch('user_names', :expires_in => 3600) > {User.all.collect {|u| [u.id,u.name]}} # names are cached for 1hr > (3600 seconds) > end > > again in your controller: > > def list > @names ||= User.names.sort > end > > in your view: > <% @names.each do |name| -%> > <%= name[0] -%> > <% end -%> > > If the names aren't cached or the cache is older than the one hour > defined in the model then the fetch method knows to go grab them > afresh. > > I'm using memcache in a more complex manner with full objects and it > works like a charm - as a matter of fact this has taken common > requests for fetching data completely off of the database. I rebuild > the cache without using expiration by implementing callbacks on > modification of the underlying data - this has taken load times for > data intensive / cmplex data sets from 20+ seconds down to an > imperceivable delay... makes clients happy to see that kind of > improvement. :) > > Naturally you will need to have the memcache service running somewhere > in your environment. > Hope that helps > Ben > > On May 26, 4:05 am, wakathane wrote: > > > hey, > > > for performance reasons i want to cache (template) variables using > > memcache, making access to data easy in templates by using a simple > > syntax like <%=users(2).name%>. this actually should tell the view to > > load the field 'name' from the model/table 'users' with id=2. it first > > tries memcache and if not found, loads the data from the and stores it > > in memcache. > > > has anyone done this before, any ready to use plugins available? :). > > if not, any ideas/suggestions on how to implement this best in ror? > > > caching partials or whole actions is not an option because of too > > complex dependencies. > > > thanks --~--~-~--~~~---~--~~ 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: memcache for variables
in your config/environment/development.rb file (or whatever environement your are configuring) config.cache_store = :mem_cache_store Depending on how much memory you want to consume you can either load your whole user model, the name to ID collection or just the users that log in. In the User model do something like: def self.names Rails.cache.fetch('user_names', :expires_in => 3600) {User.all.collect {|u| [u.id,u.name]}} # names are cached for 1hr (3600 seconds) end again in your controller: def list @names ||= User.names.sort end in your view: <% @names.each do |name| -%> <%= name[0] -%> <% end -%> If the names aren't cached or the cache is older than the one hour defined in the model then the fetch method knows to go grab them afresh. I'm using memcache in a more complex manner with full objects and it works like a charm - as a matter of fact this has taken common requests for fetching data completely off of the database. I rebuild the cache without using expiration by implementing callbacks on modification of the underlying data - this has taken load times for data intensive / cmplex data sets from 20+ seconds down to an imperceivable delay... makes clients happy to see that kind of improvement. :) Naturally you will need to have the memcache service running somewhere in your environment. Hope that helps Ben On May 26, 4:05 am, wakathane wrote: > hey, > > for performance reasons i want to cache (template) variables using > memcache, making access to data easy in templates by using a simple > syntax like <%=users(2).name%>. this actually should tell the view to > load the field 'name' from the model/table 'users' with id=2. it first > tries memcache and if not found, loads the data from the and stores it > in memcache. > > has anyone done this before, any ready to use plugins available? :). > if not, any ideas/suggestions on how to implement this best in ror? > > caching partials or whole actions is not an option because of too > complex dependencies. > > thanks --~--~-~--~~~---~--~~ 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: dump and import MySQL table w/ accents
Ensure your database.yml file has a line like: encoding: utf8 On May 26, 10:50 am, "Jeffrey L. Taylor" wrote: > I am switching to a composite primary key (string and user ID) from the Rails > conventional auto-incrementing integer primary ID. The table is large (2.5 > million records) and I'd rather not discard the contents. The > composite_primary_key gem doesn't appear to support altering the table with a > migration to do its magic, only creating a table from scratch. So I dumped > the table with mysqldump, ran the migration (table looks good), and am trying > to repopulate the table. It has accented characters and is complaining about > duplicates, apparently around words with and without accents, e.g., 'jose' and > 'josé'. I've been deleting one by hand from the dump, but it is tedious and > very slow. Emacs crawls when dealing with very large files with very long > lines. > > I just don't understand why the accents are causing problems. The string > column is utf8_general_ci collation, just like other fields in the database > with strings with accents. What do I need to specify so it will import the > dump? Is there a problem with strings with accents in composite indexes? > > The table is created with a Rails migration, but everything else is pure MySQL > utilities. > > TIA, > Jeffrey --~--~-~--~~~---~--~~ 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] Active Resource custom method using POST
I've written a small piece of code that is supposed to place an order in a order handling system. get, put and delete functions are working great but I cannot get post to function at all... the error I get back from the code below is 400 (bad request). I think it has something to do with the headers but I don't know how to get more info out of this. Is there a problem with the way I am handling the post method? Thank you for your input!! Ben ### class User < ActiveResource::Base self.site = "http://www.a_restful_api.com/api/"; self.element_name = "user" self.format = :json def place_order(input) # ... handle input constraints. input is a hash # parse the hash to end up with "key=value&key=value&key=value" body = "" input.keys.sort.each do |k| if k == input.keys.sort.first body += %Q{#{k}=#{input[k]}} else body += %Q{{k}=#{input[k]}} end end user = User.find_by_remote_id(self.user_id) header ||= make_header(user) # this function returns a hash with the various elements in the header method_string = "#{self.class.prefix}#{self.class.collection_name}/ #{self.user_id}/store/orders" resp = connection.post(method_string,body,header) 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] Re: external programs
Excuse the self reply - something that comes in handy is to capture the exit status of the external application. To do this use $?.exitstatus %x{echo "Hello World"} puts $?.exitstatus On Apr 15, 8:15 am, BenH wrote: > you may try something along this line: > > timeout(10) do > %x{sleep 12} > end > > rescue Timeout::Error > # Do something to handle the time out. > puts "The sleep command timed out" > end > > Hope that gets you going in a good direction. > BenH > > On Apr 15, 7:41 am, Svetlana Vt > wrote: > > > how i can follow to execute external programs: define, that they don't > > hung with Kernel method system or another? may be use timeout? > > > excuse me for my bad english :) > > -- > > Posted viahttp://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: external programs
you may try something along this line: timeout(10) do %x{sleep 12} end rescue Timeout::Error # Do something to handle the time out. puts "The sleep command timed out" end Hope that gets you going in a good direction. BenH On Apr 15, 7:41 am, Svetlana Vt wrote: > how i can follow to execute external programs: define, that they don't > hung with Kernel method system or another? may be use timeout? > > excuse me for my bad english :) > -- > Posted viahttp://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] SOAP WSDLFactory
I've created a method for creating a SOAP WSDL driver. I've tested this without basic auth and without SSL and it works great. The sysadmin has enabled SSL and basic auth and now I'm stuck. The error is: HTTPClient::BadResponseError: unexpected response: # Which seems to indicate a failed authentication... Here's the method: def create_record_driver # WS for creating a new record username = "username" password = "mypassword" ws_site = "https://#{BASE_SITE}/ws/CreateRecord.asmx"; wsdl = "#{ws_site}?WSDL" drv = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver drv.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE drv.options["protocol.http.basic_auth"] << [ ws_site, username, password ] return drv end Any help would be appreciated. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---