[Rails] Re: Re: country state city drop down list rails
rajeevsharma86 wrote: > Thanks Stephan Wehner , > but can you tell me a way to implement it I'm really sorry, have no time at the moment. What coverage are you looking for? You can see some of the database at http://clocklist.com "Add your friend or contact"-> City (not with Internet Explorer) Stephan > > On Fri, Aug 20, 2010 at 12:07 PM, Stephan Wehner > wrote: > >> >> -- >> 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. >> >> > > > -- > Thanks: > Rajeev sharma -- 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] Re: display records for today's date
Michael Pavling wrote: > On 20 August 2010 07:17, Srikanth Jeeva wrote: >> created_at field has datetime in it. how can i search for records in >> current date? > > Model.all(:conditions => ["created_at BETWEEN ? AND ?", Date.today, > Date.tomorrow]) Thanks for the reply,, I used this , Model.find(:all, :conditions=>["DATE(created_at) = ?", Date.today]) -- 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.
Re: [Rails] Re: country state city drop down list rails
Thanks Stephan Wehner , but can you tell me a way to implement it On Fri, Aug 20, 2010 at 12:07 PM, Stephan Wehner wrote: > ashu wrote: > > hi every one > > please tell me the recommended way to get country > > state city drop down list in rails > > any gem - plug-in tutorial > > > > thanks in advance. > > I think it's fair to say the authority on such a list is > http://www.geonames.org > > You can download the data from http://download.geonames.org/export/dump > > You'll probably get more cities than you need. > > Sorry, I have no plugin / tutorial at the moment. > > Stephan > -- > 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. > > -- Thanks: Rajeev sharma -- 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] Re: country state city drop down list rails
ashu wrote: > hi every one > please tell me the recommended way to get country > state city drop down list in rails > any gem - plug-in tutorial > > thanks in advance. I think it's fair to say the authority on such a list is http://www.geonames.org You can download the data from http://download.geonames.org/export/dump You'll probably get more cities than you need. Sorry, I have no plugin / tutorial at the moment. Stephan -- 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.
Re: [Rails] display records for today's date
On 20 August 2010 07:17, Srikanth Jeeva wrote: > created_at field has datetime in it. how can i search for records in > current date? Model.all(:conditions => ["created_at BETWEEN ? AND ?", Date.today, Date.tomorrow]) -- 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] Re: Plugin to update twitter status
Stephan Wehner wrote: > http://github.com/stephan-buckmaster/simple_twitter_post > > Uses Basic Authentication at the moment. Twitter says this will be > discontinued in a few weeks (http://dev.twitter.com/pages/oauth_faq) > I updated a week ago to OAuth (using grackle) Stephan -- 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] display records for today's date
Hi, I'm having User model & it has created_at field. If i want to find all the users who are created today. How can i write the query? created_at field has datetime in it. how can i search for records in current date? Thanks, Srikanth -- 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] Re: Trying to make a user list from 2 fields
Bob Smith wrote: > My model has two fields that I want in a customer list for an index > page. They are name and second_name. I need a way to combine them in a > collection with their id numbers so the Edit links will work. Sounds > like SQL, but I'm not sure. > > maybe something like: > SELECT name, id FROM households and SELECT second_name, id FROM > households > > just not sure how to make ONE statement from these two including > both... > > Thanks > > Bob I'm not clear what you exactly want.. If you want to display name, second name in ur page, use this in controller, Assuming ur model name is Household @households = Household.all & in the view, @households.each do |hh| hh.name + hh.second_name end this is wht u want? regards, Srikanth http://srikanthjeeva.blogspot.com -- 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] Trying to make a user list from 2 fields
My model has two fields that I want in a customer list for an index page. They are name and second_name. I need a way to combine them in a collection with their id numbers so the Edit links will work. Sounds like SQL, but I'm not sure. maybe something like: SELECT name, id FROM households and SELECT second_name, id FROM households just not sure how to make ONE statement from these two including both... Thanks Bob -- 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.
Re: [Rails] Re: country state city drop down list rails
I don't think they provide country state and cities Does the did you ever you any please suggest .. On Fri, Aug 20, 2010 at 10:30 AM, Priyanka Pathak wrote: > Hi, >There are some plugins available for country selection. >- http://github.com/rails/country_select >For US cities you may use http://github.com/mettadore/geoinfo > > -- > 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. > > -- Thanks: Rajeev sharma -- 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] Re: country state city drop down list rails
Hi, There are some plugins available for country selection. - http://github.com/rails/country_select For US cities you may use http://github.com/mettadore/geoinfo -- 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] country state city drop down list rails
hi every one please tell me the recommended way to get country state city drop down list in rails any gem - plug-in tutorial thanks in advance. -- 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.
Re: [Rails] configure create database virtual rails
no need to configure anything, all the hard work has been done for you. take a look at railstutorial.org/book, that will get you started. mysql is already configured, you will just need to start the service, which is outlined on the virtual rails site. Cheers, Jason On Thu, Aug 19, 2010 at 5:43 PM, Rich d wrote: > I have installed virtual machine and virtual rails on my laptop using > Linux mint. Im learning as I go. Everything I need comes with this > package : > > MySQL > Mongrel > Ruby1.8.7 > Mongo D.B. > Git 1.6.3.3 > Netbeans 6.8 > > so before I can run a rails application according to the tutorial I > need to configure a database and create a database. Is this correct?? > I tried apt-get install andgem install and they did not > work... > > if configuring and creating a database is the next step how do I go > about doing this? > > -- > 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. > > -- 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] Re: Why through and foreign_key not working?
Frederick Cheung wrote: > With has many through you use the :source option to tell it which of > the associations of friendships to follow to get to the desired row(s) > > Fred Now~ I need `activities`.user_id not is `activities`.id :D -- 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] Scriptaculous effect not working..
Hey so here is my code: <% if @error == true %> <%= javascript_tag "New Effect.Shake('form_holder'); return false;" %> <% end %> I know that the scriptaculous library is being included in the head of my view, but for some reason the effect never works. Im using the effect to notify the user that their login was incorrect, hence the @error variable. That variable is set in my session creating action and upon an incorrect login the new action is rendered (there is nothing inside this action). However, when i make an incorrect login and the new action is rendered, the source code contains the javascript, just nothing happens! Many thanks, jakx.12 -- 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.
Re: [Rails] Re: Storing a hash or array in the db
Thank you for your help! I'm still learning how to use MVC, and I'm still having difficulty with some of the concepts. Can I ask a follow-up quesiton on how to set this up? I will have a product that can belong to one or many sub-catagories which in turn belong to one or many catagories. The same subcatagory name can belong to two different catagories (although its referring to a different group of products). For example: Fishingline (catagory) -> Long (subcatagory) and Knives (catagory) -> Long (subcatagory), where the products in both are different. Additional requirements: - in the store, display just products in a subcatagory (under a catagory), or display all products in the catagory (products belonging to all subcatagories). - in the admin portal, be able to set the catagories and subcatagories in the product view So there needs to be a class to represent the catagories. Should there be a class for each subcatagory that has the catagory as a property? Can the products view update the catagory that the product belongs to? For displaying in the store, I currently have a store controller + views that display all of hte items. Can the store controller show the different views based on the catagory? Or should the store controller own the catagory buttons that direct to the catagory views that show the specific subset of products? Do I need view and controller for the catagory class? Thanks in advance for any advice you can provide! Madison On Tue, Aug 17, 2010 at 2:12 PM, Colin Law wrote: > On 17 August 2010 22:00, Madison Kelly wrote: > > I'm using an array to store a list of catagories that a product will > belong > > to. Since the number of catagories a product can belong to isn't set > (could > > be 1 or could be 10), I was going to use an array. Does that sound like > an > > appropriate use? > > No, I don't believe so. Provide a Categories model and have product > has_and_belongs_to_many categories (and vice versa). Or provide a > categories_products join table and use has_many through the join > table. See the Rails Guide on ActiveRecord Associations for more > details. > > Colin > > -- > 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. > > -- 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] configure create database virtual rails
I have installed virtual machine and virtual rails on my laptop using Linux mint. Im learning as I go. Everything I need comes with this package : MySQL Mongrel Ruby1.8.7 Mongo D.B. Git 1.6.3.3 Netbeans 6.8 so before I can run a rails application according to the tutorial I need to configure a database and create a database. Is this correct?? I tried apt-get install andgem install and they did not work... if configuring and creating a database is the next step how do I go about doing this? -- 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] Re: rails3 console : how to get actual sql statements
(For Rails 3) I have this in my development.rb environment file: #log ActiveRecord ActiveRecord::Base.logger = Logger.new(STDOUT) if defined? Rails::Console -- 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] Re: Depreciation warning when running a db migrate!
Colin Law wrote: > On 19 August 2010 19:25, Zack Nathan wrote: >> Hey, >> Whenever i try and run a db migrate i get this error: >> >> DEPRECATION WARNING: Rake tasks in vendor/plugins/livevalidation/tasks >> and vendor/plugins/restful-authentication/tasks are deprecated. Use >> lib/tasks instead. (called from >> /Users/Zack/.gem/ruby/1.8/gems/rails-2.3.8/lib/tasks/rails.rb:10) > > You can ignore this, it is just a warning that the plugins rake tasks > are not in what is now considered the correct folder. It is possible > that there are later versions of the plugins that sort the problem. > > Colin Ok thanks, but it still never migrates the database.. -- 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] Re: Re: Re: how to perform "most viewed"
Philip Hallstrom wrote: >> And, of course, that race condition exists in your console experiment, >> but that's not an issue in the controller method I presented earlier. > > Yes, it is. What happens when two people hit the URL that triggers that > action at the same time? Sorry I was completely forgetting about the very important rule for any GET request (such as with the show action). Get request should be idempotent! http://en.wikipedia.org/wiki/Idempotent As I realized early and posted to the effect. I do completely agree with you. -- 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.
Re: [Rails] Re: Re: how to perform "most viewed"
> Robert Walker wrote: >> Besides this. According the the Rails docs, increment_counter is >> typically used for caching aggregate values. That's not the case here >> since the field to be incremented is not related to an associated model. >> The increment_counter would make sense for things like caching the count >> of comments on a post model to prevent the SQL query that would be >> required to count the associated comments. >> >> And, of course, that race condition exists in your console experiment, >> but that's not an issue in the controller method I presented earlier. >> The @poem instance would be garbage collected at the end of the >> request-response cycle. Other methods would have to reload from the >> database anyway. So I don't see a problem using the increment! method >> here. >> >> -- >> def show >> @poem = Poem.find(params[:id]) >> @poem.increment!(:view_count) >> ... >> ... >> end >> -- > > Disregard this. Too late. I already responded :) > I see the issue presented by Philip Hallstrom now. Makes > sense. Maybe we should consider deprecating increment! given the race > condition due to multi-threading/multi-processes. Maybe. But then again it may have it's uses. Maybe you know what you're doing and really just want to update the model (assuming the non-bang version). I think it would be a good idea for the docs to mention the race condition and point people to increment_counter. increment! could also simply hand off to increment_counter, but that might have some negative side affects for existing code that rely on increment/increment!. I don't know -philip -- 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.
Re: [Rails] Re: Re: how to perform "most viewed"
> And, of course, that race condition exists in your console experiment, > but that's not an issue in the controller method I presented earlier. Yes, it is. What happens when two people hit the URL that triggers that action at the same time? Change the action to this... def show @poem = Poem.find(params[:id]) sleep(rand(10)) # to simulate something that takes awhile @poem.increment!(:view_count) ... ... end Let's say that view_count is 1 for the given poem. Hit that page with two browsers at the same time and when they both finish view_count will be 2. It should be 3. > The @poem instance would be garbage collected at the end of the > request-response cycle. True, but even quick Rails processes take a little bit of time. As soon as there is *any* time between when you retrieve the record and when it gets incremented, you have a chance for a race condition because the increment (via increment!()) isn't incrementing. It's overwriting. > Other methods would have to reload from the > database anyway. So I don't see a problem using the increment! method > here. > > -- > def show > @poem = Poem.find(params[:id]) > @poem.increment!(:view_count) > ... > ... > end > -- > -- > 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. > -- 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] Re: Re: how to perform "most viewed"
Robert Walker wrote: > Besides this. According the the Rails docs, increment_counter is > typically used for caching aggregate values. That's not the case here > since the field to be incremented is not related to an associated model. > The increment_counter would make sense for things like caching the count > of comments on a post model to prevent the SQL query that would be > required to count the associated comments. > > And, of course, that race condition exists in your console experiment, > but that's not an issue in the controller method I presented earlier. > The @poem instance would be garbage collected at the end of the > request-response cycle. Other methods would have to reload from the > database anyway. So I don't see a problem using the increment! method > here. > > -- > def show > @poem = Poem.find(params[:id]) > @poem.increment!(:view_count) > ... > ... > end > -- Disregard this. I see the issue presented by Philip Hallstrom now. Makes sense. Maybe we should consider deprecating increment! given the race condition due to multi-threading/multi-processes. -- 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] Re: Re: how to perform "most viewed"
Michael Pavling wrote: > On 19 August 2010 21:18, Philip Hallstrom wrote: >> Don't use increment. �It won't do what you want since it's only incrementing >> the value of the object and then saving it. �Not updating the value in the >> database. > > What is "saving" if not updating in the database? > >> You want to use increment_counter which calls update_counters which does >> this in the database: > > What is the result of your "u" "u1" console experiment when you use > increment_counter rather than increment? > As far as I can see it will be the same - you've got two copies of an > object loaded, and you update one, without reloading the other; of > course that can lead to race conditions and stale data. Besides this. According the the Rails docs, increment_counter is typically used for caching aggregate values. That's not the case here since the field to be incremented is not related to an associated model. The increment_counter would make sense for things like caching the count of comments on a post model to prevent the SQL query that would be required to count the associated comments. And, of course, that race condition exists in your console experiment, but that's not an issue in the controller method I presented earlier. The @poem instance would be garbage collected at the end of the request-response cycle. Other methods would have to reload from the database anyway. So I don't see a problem using the increment! method here. -- def show @poem = Poem.find(params[:id]) @poem.increment!(:view_count) ... ... end -- -- 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.
Re: [Rails] Re: how to perform "most viewed"
>> increment() will *overwrite* the value in the database, not add to it. > > Ah! That's the bit that wasn't clear to me the way you phrased it > before. Reading your post again, I can see what you mean now. The annoying thing is that if your site doesn't get much traffic increment() will appear to work. It's only when there's concurrent access that it will start to break down. This next part is for the archives... As a general rule, if you are incrementing or decrementing fields that are counters, do not use any Rails method that *set* the value and save it. Make sure the method results in a "UPDATE table SET c = c + 1" type of query. If you write your own implementation, be sure to consider the situation in which your database column is NULL. And if you're doing a lot of this, you might find this useful http://github.com/phallstrom/set_counters as well. Or not :) -philip -- 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.
Re: [Rails] Re: how to perform "most viewed"
On 19 August 2010 22:00, Philip Hallstrom wrote: > increment() will *overwrite* the value in the database, not add to it. Ah! That's the bit that wasn't clear to me the way you phrased it before. Reading your post again, I can see what you mean now. Cheers, -- 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.
Re: [Rails] Re: how to perform "most viewed"
On Aug 19, 2010, at 1:31 PM, Michael Pavling wrote: > On 19 August 2010 21:18, Philip Hallstrom wrote: >> Don't use increment. It won't do what you want since it's only incrementing >> the value of the object and then saving it. Not updating the value in the >> database. > > What is "saving" if not updating in the database? Let's say we have User u with id 123. u.foo = 1. u.increment(:foo) will execute this: update users set foo = 2 where id = 123 If I have multiple copies of User 123 lying around (different mongrels perhaps) there is a race condition. The longer I hold onto a copy of User 123 the better chance I have of losing the true value of foo since increment() will *overwrite* the value in the database, not add to it. If however I do this... User.increment_counter(:foo, 123) that will execute this: update users set foo = foo + 1 where id = 123 It doesn't matter how many times or where I call it, the *database* will contain the correct value of foo. It's very possible that my local copy "u" won't until I reload it however. > >> You want to use increment_counter which calls update_counters which does >> this in the database: > > What is the result of your "u" "u1" console experiment when you use > increment_counter rather than increment? > As far as I can see it will be the same - you've got two copies of an > object loaded, and you update one, without reloading the other; of > course that can lead to race conditions and stale data. No. increment_counter doesn't operate on an instance of the class >> u = User.find(2) >> u.login_count => 8 >> User.increment_counter(:login_count, 2) User Update (3.0ms) UPDATE "users" SET "login_count" = COALESCE("login_count", 0) + 1 WHERE ("id" = 2) => 1 >> u.login_count => 8 >> u.reload User Load (1.7ms) SELECT * FROM "users" WHERE ("users"."id" = 2) >> u.login_count => 9 -- 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] Rails - Devise - Warden and InvalidAuthenticityToken
Hi I've just uploaded my new website to my server and, after a couple of teething problems, seem to be hitting problems when I am using devise and warden to authenticate users etc. The following is the error message with sensitive information removed: Processing RegistrationsController#create (for 81.111.90.194 at 2010-08-19 21:35:43) [POST] Parameters: {"commit"=>"Sign up", "action"=>"create", "authenticity_token"=>"XXXREMOVEDXXX", "controller"=>"registrations", "user"=>{"dob"=>"XXX", "password_confirmation"=>"[FILTERED]", "firstname"=>"XXX", "password"=>"[FILTERED]", "surname"=>"XXX", "email"=>"XX"}} ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken): warden (0.10.7) [v] lib/warden/manager.rb:35:in `call' warden (0.10.7) [v] lib/warden/manager.rb:34:in `catch' warden (0.10.7) [v] lib/warden/manager.rb:34:in `call' Rendering /home/enigmaho/rails_apps/newwt/public/422.html (422 Unprocessable Entity) I have no real idea what is going wrong. It works OK on my development server at home, and everything else seems to work barring this. My environment.rb file has the following lines: config.gem 'warden' config.gem 'devise' And they have been installed in my plugins/gems directory using "rake gems:unpack" I'm using Rails 2.3.8 if that's any help. Any help would be excellent! Darren -- 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] Re: Re: Postgres, concurrency, and rails
It must be the ancient version of Rails we are using then. The postgresql_adapter requires a gem (whatever version, postgres-pr, ruby-postgres, etc) that calls itself 'postgres', and I imagine pg only responds to 'pg'. Perhaps Rails 3.0 requires either postgres OR pg. It might be possible I could modify the adapter but that is probably asking for trouble. Either way though, ruby-postgres seems to work fine so far. It no longer deadlocks. However, calling allow_concurrency = true on ActiveRecord seems to cause the server to hang. After I commented it out, however, things went fine and there was no deadlock. I do get messages from postgres such as "warning: transaction in progress", which I'm guessing is the result of my threads hitting the same table at the same time (I did this on purpose to test). I'm guessing that allow_concurrency is supposed to prevent this by making ActiveRecord queue up these transactions, but like I said it seems to make the server hang. So the question really is, can postgres handle these overlapping transactions? It seems to do a good job queueing them up so far, but I guess we'll have to see. Again, any insight is appreciated. -- 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.
Re: [Rails] Re: how to perform "most viewed"
On 19 August 2010 21:18, Philip Hallstrom wrote: > Don't use increment. It won't do what you want since it's only incrementing > the value of the object and then saving it. Not updating the value in the > database. What is "saving" if not updating in the database? > You want to use increment_counter which calls update_counters which does this > in the database: What is the result of your "u" "u1" console experiment when you use increment_counter rather than increment? As far as I can see it will be the same - you've got two copies of an object loaded, and you update one, without reloading the other; of course that can lead to race conditions and stale data. -- 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.
Re: [Rails] Re: Postgres, concurrency, and rails
On Thu, Aug 19, 2010 at 3:01 PM, Zach Brod wrote: > It seems that the supposedly 'latest' Postgres adapter, pg, doesn't work > with Rails at all, or at least version 1.2.3. You need to use > ruby-postgres. I am using pg (0.9.0) with Rails 3.0-rc and it works fine. I did have to uninstall all other Postgres gems for it to work however. -- Greg Donald destiney.com | gregdonald.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.
Re: [Rails] Re: how to perform "most viewed"
On Aug 19, 2010, at 12:50 PM, Robert Walker wrote: > nirosh wrote: >> i have a poem model. i need to display the most viewed poems. >> is there any plug inns out there to do this? > > Unless I'm missing something obvious, I wouldn't think a plugin would be > needed for this. > > poems_controller.rb > > def show > @poem = Poem.find(params[:id]) > @poem.increment!(:view_count) Don't use increment. It won't do what you want since it's only incrementing the value of the object and then saving it. Not updating the value in the database.That is to say... >> u = User.find(2) >> u1 = User.find(2) >> u.login_count => 7 >> u1.login_count => 7 >> u1.increment!(:login_count) >> u1.login_count => 8 >> u.login_count => 7 >> u.increment!(:login_count) >> User.find(2).login_count => 8 Oops! You want to use increment_counter which calls update_counters which does this in the database: UPDATE poem SET view_count = view_count + 1 WHERE id = 123 So... you want this: def show Poem(:view_count, params[:id]) end > ... > ... > end > > http://railsapi.com/doc/rails-v2.3.8/classes/ActiveRecord/Base.html#M001117 > -- > 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. > -- 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] Re: Postgres, concurrency, and rails
After some more epic Googling (literally like 10+ hours of just slogging through crap) I've gotten a little further in my search, for anyone who is having similar problems. It seems that the supposedly 'latest' Postgres adapter, pg, doesn't work with Rails at all, or at least version 1.2.3. You need to use ruby-postgres. You will have some issues with some DLL files because Postgres 8.4 uses a newer version of SSL or some sort. It is all explained here: http://rubyonrailswin.wordpress.com/2010/03/12/getting-postgresql-to-install-on-windows/ If anyone has any more insight into the concurrency thing, I would still love feedback. 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-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.
Re: [Rails] Re: how to perform "most viewed"
On 20/8/2010 3:50 AM, Robert Walker wrote: nirosh wrote: i have a poem model. i need to display the most viewed poems. is there any plug inns out there to do this? Unless I'm missing something obvious, I wouldn't think a plugin would be needed for this. poems_controller.rb def show @poem = Poem.find(params[:id]) @poem.increment!(:view_count) ... ... end ...or use update_counters http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001792 Cheers, Mohit. 20/8/2010 | 4:00 AM. -- 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] Re: Composite primary keys and :joins=>
as a follow up...I did the equivalent of: TableB.all(:select=>SELECT, :joins=>"left outer join table_a on table_a.type_key='FOOKEY' and table_a.code_key=table_b.code") and it works fine. Still curious to know if there is a way to define a belongs_to and use that association in the :joins. Thanks, Jeff On Aug 18, 10:34 pm, JeffV wrote: > I have a legacy db with the following simplified structure: > > Table-A: > type_key, code_key, name, ... # PKs are type_key and code_key, > there is no id col and I cannot alter this db > > Table-B: # each row has only the code as a foreign_key, the type_key > is hard-coded to "FOOKEY" > an_id, code, ... > > Models: > class TableB < AR::Base > set_table_name 'table_b' > set_primary_key :an_id # singular PK > > belongs_to :code_name, :class_name=>'TableA', :primary_key=>:pk_code_name, > :foreign_key=>:code > > SELECT = "*, table_a.name AS pk_name" > > def self.get_all > all(:select=>SELECT, :joins=>:code_name) > end > end > > class TableA < AR::Base > set_table_name 'table_a' > set primary_keys :type_key, :code_key # using the composite > primary keys gem 2.3.2 > > def self.find_by_pk_code_name(*args) # pk method invoked by > belongs_to in TableB > opts = args.extract_options! > pk_type_key = "FOOKEY" > pk_code_key = args.first > find([pk_type_key, pk_code_key], opts) > rescue ActiveRecord::RecordNotFound > end > end > > Console: > x=TableB.first > x.code_name # works! > TableB.get_all # fails: "element size differs (1 should be 2)" > > I believe this error is due to 2 PKs being defined for TableA yet only > 1 key is specified in the belongs_to :foreign_key. > > The problem is that a row in TableB contains only one of the PKs for > TableA, with the second PK being hard-coded to "FOOKEY". > It appears that the contents of :foreign_key=> references col names, > not methods. The SQL I want to generate is something like this: > SELECT *, table_a.name AS pk_name FROM table_b > LEFT OUTER JOIN table_a ON (table_a.code_key = table_b.code AND > table_a.type_key = 'FOOKEY') > > I cannot figure out how to use AR to make this work. Any help is much > appreciated! 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-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.
Re: [Rails] Depreciation warning when running a db migrate!
On 19 August 2010 19:25, Zack Nathan wrote: > Hey, > Whenever i try and run a db migrate i get this error: > > DEPRECATION WARNING: Rake tasks in vendor/plugins/livevalidation/tasks > and vendor/plugins/restful-authentication/tasks are deprecated. Use > lib/tasks instead. (called from > /Users/Zack/.gem/ruby/1.8/gems/rails-2.3.8/lib/tasks/rails.rb:10) You can ignore this, it is just a warning that the plugins rake tasks are not in what is now considered the correct folder. It is possible that there are later versions of the plugins that sort the problem. Colin -- 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] Re: how to perform "most viewed"
nirosh wrote: > i have a poem model. i need to display the most viewed poems. > is there any plug inns out there to do this? Unless I'm missing something obvious, I wouldn't think a plugin would be needed for this. poems_controller.rb def show @poem = Poem.find(params[:id]) @poem.increment!(:view_count) ... ... end http://railsapi.com/doc/rails-v2.3.8/classes/ActiveRecord/Base.html#M001117 -- 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.
Re: [Rails] implementing project management and event types
On 19 August 2010 18:52, richardsugg wrote: > I am implemented a simple project management application. Each > project has various events, and each event can be a different type. > Some event information is common, such as name, start date, close > date, and comments. I have a projects table which has_many events. > My plan is to have several sub-event tables, like event_get_access > which will contain an event_id field to link it to table events as > well as information specific to a "get access" event (remote access, > username, passwords, etc). Another event type might be "upgrade" > which stores information about the server to be upgraded, etc. > > So I have: > * a project which has_many events > * events which belongs_to :project > * sub-events which belong_to :event > > How do the subevents relate to event? An event will never have more > than one subevent, but it may not have any of a particular subevent. Have you looked at Single Table Inheritance, which would allow multiple types of event all in one table (rather than have subevents of different types)? Otherwise I think you could have Event has_one :sub_event_type_one has_one :sub_event_type_two and so on. Then SubEventTypeOne belongs_to :event etc. It does not matter if a particular event does not have a particular type of subevent, if you try to access event.sub_event_type_one and it does not have one then you will get nil Colin -- 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] Re: Limiting scope of :validates_uniqueness_of
Ah, ok. That did it. I see now I would want to limit the scope to the post_id column, instead of the post table. Thank you! Rob Biedenharn wrote: > On Aug 19, 2010, at 11:23 AM, Ze Ca wrote: > >> >> I'm having a hard time limiting the scope of new comments to the Post >> model. So, for validates_uniqueness_of :title in the comment.rb model, >> that uniqueness would only be attached to the post I'm commenting to, >> not globally among all comments in the application. >> >> I tried putting this in comment.rb: >> >> validates_uniqueness_of :title, :scope => :post > > :scope => :post_id > >> CACHE (0.0ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) >> Rendered rescues/_request_and_response (1.2ms) >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en >> . >> > > Rob Biedenharn > r...@agileconsultingllc.com http://AgileConsultingLLC.com/ > r...@gaslightsoftware.comhttp://GaslightSoftware.com/ -- 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.
Re: [Rails] Adding new variables to a model
Oh of course!! I can't believe I forgot that. Thanks so much!!! On Thu, Aug 19, 2010 at 12:15 PM, Philip Hallstrom wrote: > > On Aug 19, 2010, at 12:02 PM, Madison Kelly wrote: > > > Hello -- > > > > Thanks in advance for putting up with a newbie question:) > > > > I added two columns to my Products model. The db migration completed > without error, I added the items to the views, and I tested the expected > behavior on the site itself. The properties can be set, stored, and is > displayed later. I also put some validation in the model, and the errors > display perfectly. So everything is working just as I would expect. > > > > Where I ran into trouble is when I ran the unit tests I have for the > products model. I'm getting errors that say the properties are an "undefined > method". Even for test cases that don't refer to these properties, they are > returning the same error. I assume this is from referencing the model. Why > does everything work correctly on the site, but the test cases don't seem to > recognize the new properties I've added to the model? > > Don't you need to setup the test database? > > rake db:test:clone# Recreate the test database from the current > environment's database schema > rake db:test:clone_structure # Recreate the test databases from the > development structure > rake db:test:load # Recreate the test database from the current > schema.rb > rake db:test:prepare # Check for pending migrations and load the > test schema > rake db:test:purge# Empty the test database > > > > > Thanks! > > Madison > > > > > > Additional information below: > > > > (note: two new columns are has_case and case_quantity) > > > > Error: > > C:\webapp\depot>ruby -I test test/unit/product_test.rb > > Loaded suite test/unit/product_test > > Started > > EE > > Finished in 0.218401 seconds. > > 1) Error: > > test_default_case_values(ProductTest): > > NoMethodError: undefined method `has_case' for # > > test/unit/product_test.rb:53:in `test_default_case_values' > > 2) Error: > > test_if_has_case_must_have_case_quantity(ProductTest): > > ActiveRecord::UnknownAttributeError: unknown attribute: has_case > > test/unit/product_test.rb:58:in `new' > > test/unit/product_test.rb:58:in > `test_if_has_case_must_have_case_quantity' > > 3) Error: > > test_image_url(ProductTest): > > NoMethodError: undefined method `case_quantity' for # > > test/unit/product_test.rb:36:in `test_image_url' > > test/unit/product_test.rb:34:in `each' > > test/unit/product_test.rb:34:in `test_image_url' > > 4) Error: > > test_invalid_with_empty_attributes(ProductTest): > > NoMethodError: undefined method `case_quantity' for # > > test/unit/product_test.rb:10:in `test_invalid_with_empty_attributes' > > 5) Error: > > test_positive_price(ProductTest): > > NoMethodError: undefined method `case_quantity' for # > > test/unit/product_test.rb:20:in `test_positive_price' > > 6) Error: > > test_unique_title(ProductTest): > > NoMethodError: undefined method `case_quantity' for # > > test/unit/product_test.rb:47:in `test_unique_title' > > 6 tests, 0 assertions, 0 failures, 6 errors > > C:\webapp\depot> > > > > > > Model: > > class Product < ActiveRecord::Base > > has_many :orders, :through=> :line_items > > has_many :line_items > > validates_presence_of :title, :description, :image_url, :price > > validates_numericality_of :price, :case_quantity > > validate :price_must_be_at_least_a_cent, :if_case_must_have_quantity, > > :if_quantity_must_have_case > > validates_uniqueness_of :title > > validates_format_of :image_url, > > :with => %r{\.(gif|jpg|png)$}i, > > :message => 'must be a URL for GIF, JPG ' + 'or PNG > image.' > > protected > > def price_must_be_at_least_a_cent > > errors.add(:price, 'should be at least 0.01') if price.nil? || price > < 0.01 > > end > > def if_case_must_have_quantity > > if (has_case == true) && (case_quantity < 1) > > errors.add(:case_quantity, ': must set case quantity if this > product can be sold in cases') > > end > > end > > def if_quantity_must_have_case > > if (has_case == false) && (case_quantity > 0) > > errors.add(:case_quantity, ': must be 0 if product is not sold in > cases') > > end > > end > > def self.find_products_for_sale > > find(:all, :order => "title") > > end > > end > > > > > > DB migration: > > class AddCaseAndQuantityToProducts < ActiveRecord::Migration > > def self.up > > add_column :products, :has_case, :boolean, :default => false > > add_column :products, :case_quantity, :integer, :default => 0 > > end > > def self.down > > remove_column :products, :has_case > > remove_column :products, :case_quantity > > end > > end > > > > > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > > To post to
[Rails] Re: Re: Removing just leading and trailing newline characters
Jeffrey L. Taylor wrote: > Quoting Marnen Laibow-Koser : >> This is probably best done with a regular expression. >> > > Isn't this just what String#strip does? No. Strip removes all whitespace, not just newlines. > > Jeffrey Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org Sent from my iPhone -- 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.
Re: [Rails] Adding new variables to a model
On Aug 19, 2010, at 12:02 PM, Madison Kelly wrote: > Hello -- > > Thanks in advance for putting up with a newbie question:) > > I added two columns to my Products model. The db migration completed without > error, I added the items to the views, and I tested the expected behavior on > the site itself. The properties can be set, stored, and is displayed later. I > also put some validation in the model, and the errors display perfectly. So > everything is working just as I would expect. > > Where I ran into trouble is when I ran the unit tests I have for the products > model. I'm getting errors that say the properties are an "undefined method". > Even for test cases that don't refer to these properties, they are returning > the same error. I assume this is from referencing the model. Why does > everything work correctly on the site, but the test cases don't seem to > recognize the new properties I've added to the model? Don't you need to setup the test database? rake db:test:clone# Recreate the test database from the current environment's database schema rake db:test:clone_structure # Recreate the test databases from the development structure rake db:test:load # Recreate the test database from the current schema.rb rake db:test:prepare # Check for pending migrations and load the test schema rake db:test:purge# Empty the test database > > Thanks! > Madison > > > Additional information below: > > (note: two new columns are has_case and case_quantity) > > Error: > C:\webapp\depot>ruby -I test test/unit/product_test.rb > Loaded suite test/unit/product_test > Started > EE > Finished in 0.218401 seconds. > 1) Error: > test_default_case_values(ProductTest): > NoMethodError: undefined method `has_case' for # > test/unit/product_test.rb:53:in `test_default_case_values' > 2) Error: > test_if_has_case_must_have_case_quantity(ProductTest): > ActiveRecord::UnknownAttributeError: unknown attribute: has_case > test/unit/product_test.rb:58:in `new' > test/unit/product_test.rb:58:in `test_if_has_case_must_have_case_quantity' > 3) Error: > test_image_url(ProductTest): > NoMethodError: undefined method `case_quantity' for # > test/unit/product_test.rb:36:in `test_image_url' > test/unit/product_test.rb:34:in `each' > test/unit/product_test.rb:34:in `test_image_url' > 4) Error: > test_invalid_with_empty_attributes(ProductTest): > NoMethodError: undefined method `case_quantity' for # > test/unit/product_test.rb:10:in `test_invalid_with_empty_attributes' > 5) Error: > test_positive_price(ProductTest): > NoMethodError: undefined method `case_quantity' for # > test/unit/product_test.rb:20:in `test_positive_price' > 6) Error: > test_unique_title(ProductTest): > NoMethodError: undefined method `case_quantity' for # > test/unit/product_test.rb:47:in `test_unique_title' > 6 tests, 0 assertions, 0 failures, 6 errors > C:\webapp\depot> > > > Model: > class Product < ActiveRecord::Base > has_many :orders, :through=> :line_items > has_many :line_items > validates_presence_of :title, :description, :image_url, :price > validates_numericality_of :price, :case_quantity > validate :price_must_be_at_least_a_cent, :if_case_must_have_quantity, > :if_quantity_must_have_case > validates_uniqueness_of :title > validates_format_of :image_url, > :with => %r{\.(gif|jpg|png)$}i, > :message => 'must be a URL for GIF, JPG ' + 'or PNG > image.' > protected > def price_must_be_at_least_a_cent > errors.add(:price, 'should be at least 0.01') if price.nil? || price < > 0.01 > end > def if_case_must_have_quantity > if (has_case == true) && (case_quantity < 1) > errors.add(:case_quantity, ': must set case quantity if this product > can be sold in cases') > end > end > def if_quantity_must_have_case > if (has_case == false) && (case_quantity > 0) > errors.add(:case_quantity, ': must be 0 if product is not sold in > cases') > end > end > def self.find_products_for_sale > find(:all, :order => "title") > end > end > > > DB migration: > class AddCaseAndQuantityToProducts < ActiveRecord::Migration > def self.up > add_column :products, :has_case, :boolean, :default => false > add_column :products, :case_quantity, :integer, :default => 0 > end > def self.down > remove_column :products, :has_case > remove_column :products, :case_quantity > 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-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. -- You received this message because you are subscri
[Rails] Re: form_for
This is a method generated for you by rails as a result of the associtions declared in the Post and Comment models - in this case belongs_to and has_many. Comments belongs to a post, and a post can have many comments. Rails creates quite a number of theses methods in response to the association, and different associations (has_one, has_and_belongs_to_many etc.) create different sets of methods - more details in the API docs: http://edgeapi.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html collection.build is one of these methods, and the API docs explain it pretty well: "collection.build(attributes = {}, …)Returns one or more new objects of the collection type that have been instantiated with attributes and linked to this object through a foreign key, but have not yet been saved." "collection" in this case is @post.comments (None of of which has anything to do with namespaced resources...) Matt. On Aug 14, 2:23 pm, Abder-Rahman Ali wrote: > At the following:http://edgeguides.rubyonrails.org/getting_started.html > > Under: 7.4 Generating a Controller > > It mentions the following: > > <%= form_for([...@post, @post.comments.build]) do |f| %> > > Now, this is what I know: > > form_for: used to generate a form. > @post: the object form_for is bound to. > > The part I didn't get here is: > > @post.comments.build > > What does that part provide me with? > > 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-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] how to perform "most viewed"
i have a poem model. i need to display the most viewed poems. is there any plug inns out there to do this? -nirosh- -- 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] Adding new variables to a model
Hello -- Thanks in advance for putting up with a newbie question:) I added two columns to my Products model. The db migration completed without error, I added the items to the views, and I tested the expected behavior on the site itself. The properties can be set, stored, and is displayed later. I also put some validation in the model, and the errors display perfectly. So everything is working just as I would expect. Where I ran into trouble is when I ran the unit tests I have for the products model. I'm getting errors that say the properties are an "undefined method". Even for test cases that don't refer to these properties, they are returning the same error. I assume this is from referencing the model. Why does everything work correctly on the site, but the test cases don't seem to recognize the new properties I've added to the model? Thanks! Madison Additional information below: (note: two new columns are has_case and case_quantity) *Error:* C:\webapp\depot>ruby -I test test/unit/product_test.rb Loaded suite test/unit/product_test Started EE Finished in 0.218401 seconds. 1) Error: test_default_case_values(ProductTest): NoMethodError: undefined method `has_case' for # test/unit/product_test.rb:53:in `test_default_case_values' 2) Error: test_if_has_case_must_have_case_quantity(ProductTest): ActiveRecord::UnknownAttributeError: unknown attribute: has_case test/unit/product_test.rb:58:in `new' test/unit/product_test.rb:58:in `test_if_has_case_must_have_case_quantity' 3) Error: test_image_url(ProductTest): NoMethodError: undefined method `case_quantity' for # test/unit/product_test.rb:36:in `test_image_url' test/unit/product_test.rb:34:in `each' test/unit/product_test.rb:34:in `test_image_url' 4) Error: test_invalid_with_empty_attributes(ProductTest): NoMethodError: undefined method `case_quantity' for # test/unit/product_test.rb:10:in `test_invalid_with_empty_attributes' 5) Error: test_positive_price(ProductTest): NoMethodError: undefined method `case_quantity' for # test/unit/product_test.rb:20:in `test_positive_price' 6) Error: test_unique_title(ProductTest): NoMethodError: undefined method `case_quantity' for # test/unit/product_test.rb:47:in `test_unique_title' 6 tests, 0 assertions, 0 failures, 6 errors C:\webapp\depot> *Model:* class Product < ActiveRecord::Base has_many :orders, :through=> :line_items has_many :line_items validates_presence_of :title, :description, :image_url, :price validates_numericality_of :price, :case_quantity validate :price_must_be_at_least_a_cent, :if_case_must_have_quantity, :if_quantity_must_have_case validates_uniqueness_of :title validates_format_of :image_url, :with => %r{\.(gif|jpg|png)$}i, :message => 'must be a URL for GIF, JPG ' + 'or PNG image.' protected def price_must_be_at_least_a_cent errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.01 end def if_case_must_have_quantity if (has_case == true) && (case_quantity < 1) errors.add(:case_quantity, ': must set case quantity if this product can be sold in cases') end end def if_quantity_must_have_case if (has_case == false) && (case_quantity > 0) errors.add(:case_quantity, ': must be 0 if product is not sold in cases') end end def self.find_products_for_sale find(:all, :order => "title") end end *DB migration:* class AddCaseAndQuantityToProducts < ActiveRecord::Migration def self.up add_column :products, :has_case, :boolean, :default => false add_column :products, :case_quantity, :integer, :default => 0 end def self.down remove_column :products, :has_case remove_column :products, :case_quantity 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-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] Re: I'm trying to get started with AJAX and having a problem..
Bob Smith wrote: > or > > <%= javascript_tag('$("search").focus();') %> > > > as part of a view.. > > > Bob But never do that. JavaScript works best when it's in separate files, not mixed with HTML. Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- 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] Re: I'm trying to get started with AJAX and having a problem..
or <%= javascript_tag('$("search").focus();') %> as part of a view.. Bob On Jul 30, 1:02 am, Bob Smith wrote: > Found the answer. I was making it much too complicated.. > > $("search").focus(); > > did just fine > > Bob > > On Jul 23, 6:15 pm, Bob Smith wrote: > > > I'm trying to set the focus to the first (and only} field on a search > > form and having no luck. > > From searching with google, I came up with: > > > javascript_tag("Event.observe(window, 'load', function() { > > var firstForm = $A(document.getElementsByTagName('search'))[0]; > > Form.focusFirstElement(firstForm);} );") > > > no response, though. Please help > > > Bob -- 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] Re: Help with Web Game
Thank you so much for replying. A lot of that was far over my head. But the mention of HTML5 Web sockets was something I was unaware. I could easily force my userbase to use HTML5 as it's just going to be friends. There won't be any profiting in this project at all. Just something fun for maybe 10-20 people to do. -- 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] Depreciation warning when running a db migrate!
Hey, Whenever i try and run a db migrate i get this error: DEPRECATION WARNING: Rake tasks in vendor/plugins/livevalidation/tasks and vendor/plugins/restful-authentication/tasks are deprecated. Use lib/tasks instead. (called from /Users/Zack/.gem/ruby/1.8/gems/rails-2.3.8/lib/tasks/rails.rb:10) I tried moving the different plugins task rake files to lib/tasks and i got no error but the database did not migrate. How can I fix this? Many thanks, jakx12. -- 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.
Re: [Rails] implementing project management and event types
may be my option wrong. if I do your project i will do this. * a project which has_many events * events which belongs_to :project event has_one sub_event option II * a project which has_many events * events which belongs_to :project sub_event has column "sub_event_id". it just refer the sub_event table On Fri, Aug 20, 2010 at 12:57 AM, Sampath Munasinghe wrote: > May be my > > > On Fri, Aug 20, 2010 at 12:52 AM, richardsugg wrote: > >> I am implemented a simple project management application. Each >> project has various events, and each event can be a different type. >> Some event information is common, such as name, start date, close >> date, and comments. I have a projects table which has_many events. >> My plan is to have several sub-event tables, like event_get_access >> which will contain an event_id field to link it to table events as >> well as information specific to a "get access" event (remote access, >> username, passwords, etc). Another event type might be "upgrade" >> which stores information about the server to be upgraded, etc. >> >> So I have: >> * a project which has_many events >> * events which belongs_to :project >> * sub-events which belong_to :event >> >> How do the subevents relate to event? An event will never have more >> than one subevent, but it may not have any of a particular subevent. >> >> Thanks for your help on this? >> >> -- >> 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. >> >> > -- 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] Re: Help with Web Game
On Aug 19, 10:05 am, Jooma __ wrote: > [b]The Problem:[/b] I want to include PVP as an option. So if you're in > a zone and you see in your /who list another player from the opposed > faction, you can choose to attack them. But how do I implement this so > they can join in turn based combat? I was looking at Smartfox Server > lite, but this is just a project for friends and friends of friends. I'm > with HostGator and I really don't think I can install something like > Smartfox on the shared hosting server. > > Also for Chat, I was thinking of just having a database that stored the > last 30 or so entries and updated them on refresh. Is there a better way > to implement that on a shared hosting server? I think at the very least, you'll need to use a Xen-based VPS where you get root access, such as a Rackspace Cloud server. I'd look at messaging/queuing options, such as Jabber/XMPP or AMQP implementations. That'd work for both managing a turn-based combat as well as chat. You'd write it like the old MUDs. If you're willing to sacrifice HTML4 support, you can try the Websocket stuff in HTML5 and require all players to install browsers that support it (such as Chrome and Safari). I wouldn't try using a browser-refresh scheme written using Rails; a background process at the very least or a separate server using http://www.mikeperham.com/2010/04/03/introducing-phat-an-asynchronous-rails-app/ , or even using Node.js for the server-side. The Rails side would work well if you take advantage of REST to describe resources (such as, descriptions of game objects and user avatars), but not specifically to manage the combat (ephemeral, state-ful, evented system vs. the shared-nothing, stateless system that Rails and the Web is based on). So I think Redis works better than a SQL db for handling the combat states itself. The downside is that this starts getting pretty intricate. The beauty of the auto-combat system in current web-browser games is that they give the *llusion* of control, which is enough for most players (see http://blog.wolfire.com/2009/07/creating-the-illusion-of-accomplishment/). If you implement AIs as part of the gameplay, I suggest looking at making its perceived user control of the new system match the perceived user control of the old system. Good luck. Ho-Sheng Hsiao http://ruby-lambda.blogspot.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.
Re: [Rails] implementing project management and event types
May be my On Fri, Aug 20, 2010 at 12:52 AM, richardsugg wrote: > I am implemented a simple project management application. Each > project has various events, and each event can be a different type. > Some event information is common, such as name, start date, close > date, and comments. I have a projects table which has_many events. > My plan is to have several sub-event tables, like event_get_access > which will contain an event_id field to link it to table events as > well as information specific to a "get access" event (remote access, > username, passwords, etc). Another event type might be "upgrade" > which stores information about the server to be upgraded, etc. > > So I have: > * a project which has_many events > * events which belongs_to :project > * sub-events which belong_to :event > > How do the subevents relate to event? An event will never have more > than one subevent, but it may not have any of a particular subevent. > > Thanks for your help on this? > > -- > 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. > > -- 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] implementing project management and event types
I am implemented a simple project management application. Each project has various events, and each event can be a different type. Some event information is common, such as name, start date, close date, and comments. I have a projects table which has_many events. My plan is to have several sub-event tables, like event_get_access which will contain an event_id field to link it to table events as well as information specific to a "get access" event (remote access, username, passwords, etc). Another event type might be "upgrade" which stores information about the server to be upgraded, etc. So I have: * a project which has_many events * events which belongs_to :project * sub-events which belong_to :event How do the subevents relate to event? An event will never have more than one subevent, but it may not have any of a particular subevent. Thanks for your help on this? -- 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] Re: Rails3: Arel finder discovery!
Also note that you can chain "magic finders" off the association as well; so @foo.bars.find_by_name('xyzzy') will work. --Matt Jones On Aug 18, 7:35 am, AppleII717 wrote: > On Aug 18, 5:18 am, AppleII717 wrote: > \> > > > I don't know if that was possible in rails2 (e.g., @bar > > @foo.bars.find(:conditions => "xxx")) > > > Not sure I have a use for it, but it was interesting that you can > > filter a nested has_many relationship. > > I guess it was a learning experience for me. I don't think I every saw > an example where you can filter a nested relation. Tried it in rails > 2.3.8 and it worked - so it was not a discovery - except for me. -- 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] Re: Ruby question, max length of strings
On Aug 19, 3:14 am, "Jeffrey L. Taylor" wrote: > Quoting Paul Harrington : > > > > > > > Paul Harrington wrote: > > > Jeffrey L. Taylor wrote: > > >> Am I correct in assuming that the max length of a string is 65,535 on a > > >> 32 bit > > >> platform? Anyway around this, other classes, 64 bit platform? > > > >> TIA, > > >> Jeffrey > > > > What would make you assume this? Simplest demonstration: > > > > irb(main):004:0> s = "a"*7;nil > > > => nil > > > irb(main):005:0> s.size > > > => 7 > > > irb(main):006:0> > > > > Also, keep in mind Ruby has no separate representation for raw 8bit > > > data. Only Strings. How would it be able to store a 65KB+ file in > > > memory? > > > > The only limit to Ruby string is is available memory. > > > btw that irb session was > > irb(main):001:0> RUBY_VERSION > > => "1.9.1" > > irb(main):002:0> RUBY_PLATFORM > > => "i386-mingw32" > > I find the same results. Checking further, I find that it's MySQL TEXT column > that is limited to 65,535 bytes. > Indeed. However, if you specify a :limit value higher than 65535 in the migration that creates the text column Rails will promote it to a 'mediumtext', which has a limit of (I think) 16M. Pushing the limit past *that* will again promote the column to 'longtext', which has a limit >2G. --Matt Jones -- 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] Re: need some opinions
[Please quote when replying -- it makes the discussion easier to follow.] Preacher wrote: [...] > I don't know why, but I have to specify the first @post from the json > content I'm parsing even though my query only returns one result. Then you should find out why. Is the JSON returning an array, perchance? > > I hadn't thought of defining the page in the models What? I have no idea what you're talking about here, and you didn't quote what you were referring to. > hmm time to > create a new branch. Thanks for the idea. I'm not sure I gave you that idea... Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- 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.
Re: [Rails] Re: Removing just leading and trailing newline characters
Quoting Marnen Laibow-Koser : > Priya Saini wrote: > > Hi: > > > > I am using FCKeditor in one of my form, when i copy and paste something > > into it using WordPaste, it appends few newlines at the beginning and at > > the end. > > How can i strip just those \n without effecting the inbetween newlines > > and the formatting. > > > > This is probably best done with a regular expression. > Isn't this just what String#strip does? 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-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] Re: Subclassing a model
Oh thanks. It seems, I not see wood for trees... -- 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] "Getting Started with Rails", Postgres, db:create
Hello; I have begun the "Getting Started with Rails" guide at http://guides.rubyonrails.org/getting_started.html which is supposed to create a simple blog. I execute the command "rails blog -d postgresql" without incident. I am having trouble with the next command in the tutorial: "rake db:create". The first time, I received the messages: FATAL: role "blog" does not exist ... Couldn't create database for {"encoding"=>"unicode", "username"=>"blog", "adapter"=>"postgresql", "database"=>"blog_development", "pool"=>5, "password"=>"yyy"} So I created the postgres account blog and gave that account the ability to create databases and users. Now that same command ""rake db:create"" yields these messages: undefined method `quote_ident' for PGconn:Class ... Couldn't create database for {"encoding"=>"unicode", "username"=>"blog", "adapter"=>"postgresql", "database"=>"blog_development", "pool"=>5, "password"=>"yyy"} So what is the issue here? Should I have created the three user accounts before hand? Could I just create the "blog" database before hand at the postgres prompt? If so, are there any tables that the "rails blog -d postgresql" creates? Thank you for your help. P.S. my config/database.yml looks like this: development: adapter: postgresql encoding: unicode database: blog_development pool: 5 username: blog password: yyy test: adapter: postgresql encoding: unicode database: blog_test pool: 5 username: blog password: yyy production: adapter: postgresql encoding: unicode database: blog_production pool: 5 username: blog password: yyy -- 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] Postgres, concurrency, and rails
I work on a fairly large website that uses Ruby 1.8.6 and Rails 1.2.3. We cannot upgrade as it will hopelessly break our code. We are working on a new version in Java but for the next year at least we are stuck with the legacy system. We use the latest version of Postgresql for the database using the postgres-pr gem. I am attempting to implement cron tasks within the system using Rufus Scheduler, which is sort of a lighter-weight version of BackgrounDRb. I found very quickly that if I have 2 tasks (threads) running and they both attempt to use ActiveRecord, they deadlock. Supposedly ActiveRecord has a means of enabling concurrency, however the postgres-pr adapter does not support this. I've been trying without luck to install one of the alternative postgres adapters that supposedly support concurrency. The 'pg' one appears to be the latest and official gem, and it installs fine. However, when I attempt to access a page, I get: "no such file to load -- postgres". I have scoured Google for this error string, but the results have not been helpful. So my first question is: what's the deal with this? Also: How do you guys use threads in your Rails apps? By the way, I am developing on a Windows box, though our production systems are FreeBSD. Thanks If you want to continue reading, I have more random notes: I did attempt to install some of the deprecated gems, with no success. The old postgres gem and ruby-pg fail when trying to build native extensions, even when I point them to the postgres install dir (I probably don't have the necessary dev tools on my workstation). Ruby-postgres (the older version of pg) installs find but doesn't play nicely with the latest version of postgresql, throwing operating system errors. Really all of this should matter though as the pg gem is the one I should be using. Is there a way to get concurrency working with postgres-pr, or does using that adapter mean you just can't use threads? Seems pretty piss poor, but typical I guess. Even if I do get the adapter working, do I have to worry about deadlock in other parts of Rails besides ActiveRecord? -- 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] Re: need some opinions
Earlier this year, I started going for HTML 5. I don't know why, but I have to specify the first @post from the json content I'm parsing even though my query only returns one result. I hadn't thought of defining the page in the modelshmm time to create a new branch. Thanks for the idea. -- 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.
Re: [Rails] Limiting scope of :validates_uniqueness_of
On Aug 19, 2010, at 11:23 AM, Ze Ca wrote: I'm having a hard time limiting the scope of new comments to the Post model. So, for validates_uniqueness_of :title in the comment.rb model, that uniqueness would only be attached to the post I'm commenting to, not globally among all comments in the application. I tried putting this in comment.rb: validates_uniqueness_of :title, :scope => :post :scope => :post_id but got this error message in my terminal: Processing CommentsController#create (for 127.0.0.1 at 2010-08-16 21:28:32) [POST] Parameters: {"comment"=>{"title"=>"rent"}, "commit"=>"Submit Your Comment", "authenticity_token"=>"z5AzsFgaJPdvGiTyy3Yeyb8f0RV+dmpdw5PanAadjOw=", "game_id"=>"5"} Post Load (0.2ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) CACHE (0.0ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) Response Load (0.0ms) SQLite3::SQLException: no such column: comments.posts: SELECT "comments".id FROM "comments" WHERE ("comments"."title" = 'rent' AND "comments".post = 5) LIMIT 1 ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: comments.post: SELECT "comments".id FROM "comments" WHERE ("comments"."title" = 'rent' AND "comments".post = 5) LIMIT 1): app/controllers/comments_controller.rb:4:in `create' Rendered rescues/_trace (110.5ms) Rendered rescues/_request_and_response (1.2ms) Rendering rescues/layout (internal_server_error) -- 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 . Rob Biedenharn r...@agileconsultingllc.com http://AgileConsultingLLC.com/ r...@gaslightsoftware.com http://GaslightSoftware.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.
Re: [Rails] Subclassing a model
On 19 August 2010 16:05, Fritz Trapper wrote: > Is it possible to define a subclass for a model, that defines additional > data columns, which are stored in a separate table? > > Is there any description, how to do this? You can certainly subclass a model. Then the subclass could have a :has_one relationship to another model with the extra columns which the superclass doesn't have. If you want to make it transparent, you can delegate the calls for the extra tables in the associated model, so instead of: foo.bar.extra_value you can call: foo.extra_value -- 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] Re: Subclassing a model
David J. Hamilton wrote: > On Thu, Aug 19, 2010 at 8:05 AM, Fritz Trapper > wrote: >> Is it possible to define a subclass for a model, that defines additional >> data columns, which are stored in a separate table? > > What you are describing is "Multiple Table Inheritance". I don't > think stock rails handles this. Rails supports "Single Table > Inheritance"[1] in which you'll store the union of all column types in > the base table. But you could use has_one. Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- 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] Re: Languages
Frederick Cheung wrote: > On Aug 19, 1:26�pm, Marnen Laibow-Koser wrote: >> By contrast, fast_gettext (which works with the Rails I18N >> infrastructure) works like GNU Gettext: it uses the translatable strings >> themselves as keys ("Welcome to my site!"), so that your view files are >> still readable and all hell doesn't break loose if you miss a key. �It >> stores the translated strings in industry-standard PO files, which >> professional translators can be assumed to know how to deal with. > > If the key is the translatable string, how do you handle the case > where in english (or whatever your source language is) two things > have the same text but they don't in one of the languages you're > translating into? I understand the possibility, but I've never run into that in practice. I believe there are ways to disambiguate. > > Fred Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- 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.
Re: [Rails] Subclassing a model
On Thu, Aug 19, 2010 at 8:05 AM, Fritz Trapper wrote: > Is it possible to define a subclass for a model, that defines additional > data columns, which are stored in a separate table? What you are describing is "Multiple Table Inheritance". I don't think stock rails handles this. Rails supports "Single Table Inheritance"[1] in which you'll store the union of all column types in the base table. [1] http://api.rubyonrails.org/classes/ActiveRecord/Base.html > Is there any description, how to do this? For STI make a table for the base class and subclass arbitrarily. -- med vänlig hälsning David JH -- 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] Limiting scope of :validates_uniqueness_of
I'm having a hard time limiting the scope of new comments to the Post model. So, for validates_uniqueness_of :title in the comment.rb model, that uniqueness would only be attached to the post I'm commenting to, not globally among all comments in the application. I tried putting this in comment.rb: validates_uniqueness_of :title, :scope => :post but got this error message in my terminal: Processing CommentsController#create (for 127.0.0.1 at 2010-08-16 21:28:32) [POST] Parameters: {"comment"=>{"title"=>"rent"}, "commit"=>"Submit Your Comment", "authenticity_token"=>"z5AzsFgaJPdvGiTyy3Yeyb8f0RV+dmpdw5PanAadjOw=", "game_id"=>"5"} Post Load (0.2ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) CACHE (0.0ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) Response Load (0.0ms) SQLite3::SQLException: no such column: comments.posts: SELECT "comments".id FROM "comments" WHERE ("comments"."title" = 'rent' AND "comments".post = 5) LIMIT 1 ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: comments.post: SELECT "comments".id FROM "comments" WHERE ("comments"."title" = 'rent' AND "comments".post = 5) LIMIT 1): app/controllers/comments_controller.rb:4:in `create' Rendered rescues/_trace (110.5ms) Rendered rescues/_request_and_response (1.2ms) Rendering rescues/layout (internal_server_error) -- 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] Subclassing a model
Is it possible to define a subclass for a model, that defines additional data columns, which are stored in a separate table? Is there any description, how to do this? -- 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] Re: Languages
On Aug 19, 1:26 pm, Marnen Laibow-Koser wrote: > By contrast, fast_gettext (which works with the Rails I18N > infrastructure) works like GNU Gettext: it uses the translatable strings > themselves as keys ("Welcome to my site!"), so that your view files are > still readable and all hell doesn't break loose if you miss a key. It > stores the translated strings in industry-standard PO files, which > professional translators can be assumed to know how to deal with. If the key is the translatable string, how do you handle the case where in english (or whatever your source language is) two things have the same text but they don't in one of the languages you're translating into? Fred > > > and given your experience explain what > > advantages a switch/utilization of fast gettext would > > provide. > > Gettext is easier to work with. > > > Also, would there be a steep learning curve by switching? > > I don't know. I was using gettext before Rails I18N existed, so when > Rails I18N came out, I looked at the default I18N mechanism, concluded > it was clumsier than gettext, and went on using gettext (but this time > as a Rails I18N plugin). > > Gettext is so simple, however, that I can't imagine that t would be > difficult to learn. What *might* be time-consuming is switching your > views to use gettext-style string keys. > > But really, do your own research. Install gettext and try converting a > view or two. Seehttp://github.com/marnen/quorum2if you want to see > what views done with gettext look like. > > > > > Your thoughts would be much appreciated. > > > Regards > > > David > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...@marnen.org > > Sent from my iPhone > -- > 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-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] Re: no route matches ..... for form_remote_tag
Thanks Greg. I've added the following to my routes.rb: map.add_groups '/users/add_groups/:id', :controller => 'users', :action => 'add_groups' And changed url in form_remote_tag to: <% form_remote_tag :update => 'divgrouptable', :url => add_groups_path(@user) do %> ... and got it to work. However, I cannot say I understand why I'd have to do this. I don't really want to map the add_groups method to any url. In my original example I was specifying the method name and the controller name in the url: <% form_remote_tag :url => { :controller => :users, :action => :add_groups } do %> which should tell rails everything it needs to know to invoke the right method in the right controller, routing should not have anything to do with that. I understand that it obviously does but I don't understand why. Greg Donald wrote: > On Tue, Aug 17, 2010 at 6:29 PM, Tomasz Romanowski > wrote: >> >> I do have an "add_groups" method in UsersController. I have not messed >> with routes.rb, just a standard mapping automatically added by scaffold: >> >> map.resources :users > > A route to :add_groups isn't provided by the map.resources :users > entry, you have to add a custom route for that action. > > http://api.rubyonrails.org/classes/ActionController/Resources.html > > You can see what routes you have available by running `rake routes`. > > > -- > Greg Donald > destiney.com | gregdonald.com -- 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] Re: need some opinions
Preacher wrote: > I have some helper code that I let get out of hand. I have a number of > show actions that are routed by 'controller/:permalink' and three show > actions that are not. The blog controller's show action gets its page > title, meta description, and meta keywords by parsing some json > content from another site over which I have limited control. The > messages and site_images models have no permalink column. This is what > I've written to get all this to work right, but it looks really ugly > (and potentially brittle) to me. I'm open to suggestions on how to DRY > this up and make it solid. (I'm sticking with 2.3.8 for a while before > I tackle 3, so if you could limit your suggestions to Rails 2) > > > def page > if controller_name == 'blog' and action_name == 'show' > page = StaticPage.find(:first, :conditions => { :url => > 'rescue' }) > elsif controller_name == 'messages' and action_name == 'show' > page = StaticPage.find(:first, :conditions => { :url => > 'rescue' }) > elsif controller_name == 'site_images' and action_name == 'show' > page = StaticPage.find(:first, :conditions => { :url => > 'rescue' }) > elsif action_name == 'show' > page = @model_name.find_by_permalink(params[:permalink]) > else > page = StaticPage.find(:first, :conditions => { :url => > "#{controller_name}/#{action_name}" }) || > StaticPage.find(:first, :conditions => { :url => 'rescue' }) > end > end Yuck! That should all be handled in your routes file. > > def page_title > if controller_name == 'blog' and action_name == 'show' > title = @post.first['title'] > else > title = page.title || 'domain.com' > end > %(#{title}) > end > I think you've tried to DRY up your helpers past the point of sensibility, and wound up with something so generic that it doesn't make sense. Also: @post.first ? @post is an array of multiple posts? If so, then its name should be @posts. > def meta(name, content) > %( ) > end That looks OK -- if you need a helper for this. I'm not sure why you would. Note also that the /> is only valid if you're using XHTML (which you shouldn't be) or HTML 5. If you're using HTML 4, get rid of the slash and install the html_output plugin. > > def meta_description > if controller_name == 'blog' and action_name == 'show' > parse_meta_description(@post.first['content']) > else > page.meta_description > end > end > > def meta_keywords > if controller_name == 'blog' and action_name == 'show' > parse_meta_keywords(@post.first['content']) > else > page.meta_keywords > end > end Why not just have these as model methods? > > > Thanks in advance Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- 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] Re: Student-course system
Prash Padm wrote: > Thanks. I understood the models and controllers. I'm not able to > understand how to add the code when it comes to enrolling students. Then you need to read the Rails associations guide. Then write some Cucumber stories and try it! Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- 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.
Re: [Rails] Re: Problems installing Flotilla - no such file -- FileUtils
On 18 August 2010 22:15, Matthias Bauer wrote: > Just in case you haven't solved this yet: Install the plugin from > http://github.com/jhaagmans/flotilla.git instead - FileUtils is now > 'fileutils'. OK, thanks. I got round it by manually copying the files that install.rb was attempting to copy. Colin > > -Matt > > On Jul 6, 3:53 pm, Colin Law wrote: >> Hi >> >> I am attempting to install the Flotilla plugin for the flot javascript >> charting library. >> >> I have tried to install Flotilla using >> ruby script/plugin install git://github.com/joshuamiller/flotilla.git -- 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] Help with Web Game
Hello. I worked with Ruby on Rails professionally for a little under a year, but then got a new job and have been a flash developer for the last 2.5 years. So I'm extremely rusty with Rails. [b]What I'm doing:[/b] I want to make a small browser text based RPG with the option to use flash. (So people can play at work). [b]The Focus:[/b] Ideally I'd like people to be able to control their actions in the fight instead of just reading through the log of their auto attacks after. I'm thinking you can have 8 slots to remember spells/abilities to be able to use while in combat. Kind of like old school EverQuest. [b]The Problem:[/b] I want to include PVP as an option. So if you're in a zone and you see in your /who list another player from the opposed faction, you can choose to attack them. But how do I implement this so they can join in turn based combat? I was looking at Smartfox Server lite, but this is just a project for friends and friends of friends. I'm with HostGator and I really don't think I can install something like Smartfox on the shared hosting server. Also for Chat, I was thinking of just having a database that stored the last 30 or so entries and updated them on refresh. Is there a better way to implement that on a shared hosting server? Any ideas or theories would be really appreciated. If I can't find a solution I may have to change up how combat works so that you just manage the AI of your character and when to use their spells. Something like in Dragon Age. -- 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] Re: Re: error_messages_for doesn't work
Bla ... wrote: > I try to put in quotes, but it also doesn't works... Can you paste the content that it renders? Also, does anything scroll by in your server window when you try this? Additionally, wanted to mention that error_messages_for was removed from Rails 3, though available as a plugin. So maybe consider just going with a custom solution now. Here is an snippet that I've used, though note it is in HAML, not ERB. # views/shared/_error_messages.html.haml - if target.errors.any? #errorExplanation %h2= "#{pluralize(target.errors.count, 'error')} prohibited this record from being saved:" %ul - target.errors.full_messages.each do |message| %li= message Then used with # views/thingy/_form.html.haml #errors= render 'shared/error_messages', :target => @company You get a bit more control over what is going on here and are protected against the imminent removal of the helper. -- 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] Re: Test unit results display for every rake task
Stewart wrote: > I have not noticed this before but its a little strage. Every time I > run a rake task the results of a test suite are displayed. EG > > Does anyone have any idea why each rake task is loading test::unit ? > Not a biggie but just had me a bit puzzled. When you start your console does it tell you "Loading test environment"? And if so, interesting that you've been able to develop / test at all without some major issues. As Jason mentioned it seems like ENV set. Does echo RAILS_ENV yield anything? -- 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] Re: Languages
dbkbali wrote: > On Aug 3, 11:25�pm, Marnen Laibow-Koser wrote: >> RailsI18Nis not "really nice". �I recommend fast_gettext instead. >> > > Marnen, > > I am currently working on a multiple language application using rails > I18n and globalize2 to facilitate > the rendering of our application's static and activerecord database > fields in multiple languages. > > Not knowing much about fast_gettext except what I have read on the > github page, could you elaborate on your comment > that I18n is not very nice? Rails I18N seems needlessly complex to me, and uses symbolic keys ("application.welcome") so that your view files are not easily readable. It also stores the translated strings in YAML files. I don't think it handles pluralization as well as gettext, though I could be wrong. By contrast, fast_gettext (which works with the Rails I18N infrastructure) works like GNU Gettext: it uses the translatable strings themselves as keys ("Welcome to my site!"), so that your view files are still readable and all hell doesn't break loose if you miss a key. It stores the translated strings in industry-standard PO files, which professional translators can be assumed to know how to deal with. > and given your experience explain what > advantages a switch/utilization of fast gettext would > provide. Gettext is easier to work with. > Also, would there be a steep learning curve by switching? I don't know. I was using gettext before Rails I18N existed, so when Rails I18N came out, I looked at the default I18N mechanism, concluded it was clumsier than gettext, and went on using gettext (but this time as a Rails I18N plugin). Gettext is so simple, however, that I can't imagine that t would be difficult to learn. What *might* be time-consuming is switching your views to use gettext-style string keys. But really, do your own research. Install gettext and try converting a view or two. See http://github.com/marnen/quorum2 if you want to see what views done with gettext look like. > > Your thoughts would be much appreciated. > > Regards > > David Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org Sent from my iPhone -- 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] Re: respond_to json gives error: no route matches "/schedules/list.json" with {:method=>:get}
neigaard wrote: > Bumping this, I need some help please :) Do you have list.json.erb file in your app/view/ ? -- 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] Re: Removing just leading and trailing newline characters
Priya Saini wrote: > Hi: > > I am using FCKeditor in one of my form, when i copy and paste something > into it using WordPaste, it appends few newlines at the beginning and at > the end. > How can i strip just those \n without effecting the inbetween newlines > and the formatting. > This is probably best done with a regular expression. > > TIA, > Priya Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org Sent from my iPhone -- 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] unable to stop rails application running as window service
hi, I having a rails application running as windows service and its running ok as service but as i tried stop it using service.msc service box ,it appears to be stopped but its effect is still there and when i restarted the machine only then it stopped actully . i written a batch file and converted it in to windows service the conten ofmy batch file are ruby script\sever -p 3000 could you please help me out -- 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.
Re: [Rails] Test unit results display for every rake task
You're loading the test environment. Somewhere you have RAILS_ENV=test or ENV["RAILS_ENV"] = "test" or it's been exported to your shell environment for some reason. Jason On Aug 19, 2010, at 6:33 AM, Stewart wrote: > I have not noticed this before but its a little strage. Every time I > run a rake task the results of a test suite are displayed. EG > > > ~/Documents/City Uni Work/Final Project/code/server (master)$ rake > db:drop > (in /Users/stewartmatheson/Documents/City Uni Work/Final Project/code/ > server) > Loaded suite /Users/stewartmatheson/rails3install/bin/rake > Started > > Finished in 0.000193 seconds. > > 0 tests, 0 assertions, 0 failures, 0 errors > > > Strange right... I decided to roll a testapp to make sure it was not > something to do with my rails installation. Its not. > > ~/code/rails/testapp $ rake db:create > (in /Users/stewartmatheson/code/rails/testapp) > testapp_development already exists > ~/code/rails/testapp $ rake db:migrate > (in /Users/stewartmatheson/code/rails/testapp) > ~/code/rails/testapp $ rake test:units > (in /Users/stewartmatheson/code/rails/testapp) > ~/code/rails/testapp $ > > > Does anyone have any idea why each rake task is loading test::unit ? > Not a biggie but just had me a bit puzzled. > > -- > 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. > -- 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] Re: Languages
On Aug 3, 11:25 pm, Marnen Laibow-Koser wrote: > Leonardo Mateo wrote: > > On Tue, Aug 3, 2010 at 11:06 AM, Pale Horse > > wrote: > > >> I've not read this, though I imagine it to be overkill for my purposes. > > Really? > > You should read it. That's how rails works withi18n. Overkill would > > be to implement a different solution when a lot (and I mean a LOT) of > > people already worked it out in a really nice way. > > RailsI18Nis not "really nice". I recommend fast_gettext instead. > Marnen, I am currently working on a multiple language application using rails I18n and globalize2 to facilitate the rendering of our application's static and activerecord database fields in multiple languages. Not knowing much about fast_gettext except what I have read on the github page, could you elaborate on your comment that I18n is not very nice? and given your experience explain what advantages a switch/utilization of fast gettext would provide. Also, would there be a steep learning curve by switching? Your thoughts would be much appreciated. Regards David > > If you think that translate an application to 6 different languages > > doesn't need an elegant and easy-to-maintain solution, then you're in > > trouble. > > Agreed. > > > > >>> Or is your question specifically related to how to store the user's > >>> preferred language. > > >> What I really want is to render a different column based on the session > >> data. > > No, you really don't. You want to use one of the existingI18N > solutions -- and you don't want to add a column to the DB every time you > need to support another language. > > > If you want to do that, it's a different story. You don't need to ask > > anybody to do that, just make a case/when structure and you'll be on > > your way. > > But don't do it. > > > > > -- > > Leonardo Mateo. > > There's no place like ~ > > 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-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] Re: Re: error_messages_for doesn't work
I try to put in quotes, but it also doesn't works... -- 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] Test unit results display for every rake task
I have not noticed this before but its a little strage. Every time I run a rake task the results of a test suite are displayed. EG ~/Documents/City Uni Work/Final Project/code/server (master)$ rake db:drop (in /Users/stewartmatheson/Documents/City Uni Work/Final Project/code/ server) Loaded suite /Users/stewartmatheson/rails3install/bin/rake Started Finished in 0.000193 seconds. 0 tests, 0 assertions, 0 failures, 0 errors Strange right... I decided to roll a testapp to make sure it was not something to do with my rails installation. Its not. ~/code/rails/testapp $ rake db:create (in /Users/stewartmatheson/code/rails/testapp) testapp_development already exists ~/code/rails/testapp $ rake db:migrate (in /Users/stewartmatheson/code/rails/testapp) ~/code/rails/testapp $ rake test:units (in /Users/stewartmatheson/code/rails/testapp) ~/code/rails/testapp $ Does anyone have any idea why each rake task is loading test::unit ? Not a biggie but just had me a bit puzzled. -- 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] How to reduce number of queries
Hi , presently i have one problem, Ex: i have 6 services SERVICES = { :project_title => 'Tilte', :project_description => 'Description', :created_at => 'Created At', } In these way i have 8 services For each service i would like to give 4 permissions 1)create 2)read 3)write 4) update all services are having same permissions But know when i am writing the code Site::SERVICES.keys.each do |service_key| @site= User.new(:service_name => Userr::SERVICES[service_key.to_sym],:user_id => partner_id, :user_type => "Partner") @site.read_access = true @site.create_access = true @site.update_access = true end It is raising 8 Queiries for 8 Services and if services number increases then Number of queries are also increases So It is not good I want to find the solution with a single Query !!! Is it Possible?? -- 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] How to display a Model Box as Rails response
I am using jquery colorbox plugin as my popup/modal dialog box solution in my site. When I give a js response to client, I want to open a popup modal dialog box as the response. I wrote the following code in my response1.js.erb just to test the creation of popup box $.colorbox(); I am getting the Javascript response correctly from server but while it is getting executed on the browser, firebug reports error like $.colorbox() is not a function how else can I do the task? please help. All my related javascripts(jquery,colorbox) are getting loaded properly when the page loads (i checked the page source html file) -- 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] Re: Why through and foreign_key not working?
On Aug 19, 10:17 am, Howl Wong wrote: > I need SQL : > > SELECT `activities`.* FROM `activities` INNER JOIN `friendships` ON > `activities`.user_id = `friendships`.friend_id WHERE > `friendships`.user_id = 1 > > My User Model code: > > has_many :friendships, :dependent => :destroy > has_many :friends, :through => :friendships > has_many :activities > ## > has_many :friends_activities, :foreign_key => :user_id, :class_name => > 'Activity', :through => :friendships, :source => :friend > > Rails3 return: > > ON `activities`.id = `friendships`.friend_id ??! :foreign_key is > ignored > > Why ? With has many through you use the :source option to tell it which of the associations of friendships to follow to get to the desired row(s) Fred > -- > 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-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] Why through and foreign_key not working?
I need SQL : SELECT `activities`.* FROM `activities` INNER JOIN `friendships` ON `activities`.user_id = `friendships`.friend_id WHERE `friendships`.user_id = 1 My User Model code: has_many :friendships, :dependent => :destroy has_many :friends, :through => :friendships has_many :activities ## has_many :friends_activities, :foreign_key => :user_id, :class_name => 'Activity', :through => :friendships, :source => :friend Rails3 return: ON `activities`.id = `friendships`.friend_id ??! :foreign_key is ignored Why ? -- 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] need some opinions
I have some helper code that I let get out of hand. I have a number of show actions that are routed by 'controller/:permalink' and three show actions that are not. The blog controller's show action gets its page title, meta description, and meta keywords by parsing some json content from another site over which I have limited control. The messages and site_images models have no permalink column. This is what I've written to get all this to work right, but it looks really ugly (and potentially brittle) to me. I'm open to suggestions on how to DRY this up and make it solid. (I'm sticking with 2.3.8 for a while before I tackle 3, so if you could limit your suggestions to Rails 2) def page if controller_name == 'blog' and action_name == 'show' page = StaticPage.find(:first, :conditions => { :url => 'rescue' }) elsif controller_name == 'messages' and action_name == 'show' page = StaticPage.find(:first, :conditions => { :url => 'rescue' }) elsif controller_name == 'site_images' and action_name == 'show' page = StaticPage.find(:first, :conditions => { :url => 'rescue' }) elsif action_name == 'show' page = @model_name.find_by_permalink(params[:permalink]) else page = StaticPage.find(:first, :conditions => { :url => "#{controller_name}/#{action_name}" }) || StaticPage.find(:first, :conditions => { :url => 'rescue' }) end end def page_title if controller_name == 'blog' and action_name == 'show' title = @post.first['title'] else title = page.title || 'domain.com' end %(#{title}) end def meta(name, content) %( ) end def meta_description if controller_name == 'blog' and action_name == 'show' parse_meta_description(@post.first['content']) else page.meta_description end end def meta_keywords if controller_name == 'blog' and action_name == 'show' parse_meta_keywords(@post.first['content']) else page.meta_keywords end end Thanks in advance -- 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] Developer wanted for Rails-Mongo Knowledge Exchange improvements
We are searching for a developer to fork a Rails-based open source Knowledge Exchange (see shapado.com) and add some innovative features and extensions to this excellent codebase. The work will first involve installing and maintaining the codebase and some customizations to presentation layer. If the KE fork works well ( it's stable code, so it should be fine) , the project will lead to substantial custom coding, biz app integration work and single sign-on, web services, etc. with possible contributions back to the Shapado community. Note that this is not a MySQL database data layer , so some knowledge or interest in NOSQL would be helpful. Source code here: gitorious.org/shapado/ Thanks much, Steve -- 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] Re: bundler 1.0.0 RC makes me crazy
> We have exactly the same problem with slightly different server config. > Somehow Bundler, Passenger or whatever is not finding gems which are > installed directly from git repos. If I vendor git gems like this: We have the exact same issue, Matias. It only occurred today after we switched to Ruby Enterprise Edition, which I see you are using as well. -- 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.
Re: [Rails] Re: Ruby question, max length of strings
Quoting Paul Harrington : > Paul Harrington wrote: > > Jeffrey L. Taylor wrote: > >> Am I correct in assuming that the max length of a string is 65,535 on a > >> 32 bit > >> platform? Anyway around this, other classes, 64 bit platform? > >> > >> TIA, > >> Jeffrey > > > > What would make you assume this? Simplest demonstration: > > > > irb(main):004:0> s = "a"*7;nil > > => nil > > irb(main):005:0> s.size > > => 7 > > irb(main):006:0> > > > > Also, keep in mind Ruby has no separate representation for raw 8bit > > data. Only Strings. How would it be able to store a 65KB+ file in > > memory? > > > > The only limit to Ruby string is is available memory. > > btw that irb session was > irb(main):001:0> RUBY_VERSION > => "1.9.1" > irb(main):002:0> RUBY_PLATFORM > => "i386-mingw32" I find the same results. Checking further, I find that it's MySQL TEXT column that is limited to 65,535 bytes. Thank you, Jeffrey irb(main):001:0> s = "a"*7;nil => nil irb(main):002:0> s.size => 7 irb(main):003:0> RUBY_VERSION => "1.8.7" irb(main):004:0> RUBY_PLATFORM => "i586-linux" irb(main):005:0> -- 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] Re: image_submit_tag
Srikanth Jeeva wrote: > Hi Im using image_submit_tag to submit my form. works fine.. but the > image is displayed with border. > > I used border => 0 but no use. > > This is my code. > > <%= image_submit_tag "../images/upload.png", :border => 0 %> > > any ideas?? > > Regards, > Srikanth I used this & it worked, <%= image_submit_tag "../images/upload.png", :style => "border: none;" %> -- 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.
Re: [Rails] image_submit_tag
please check yours css once On Thu, Aug 19, 2010 at 12:20 PM, Srikanth Jeeva wrote: > Hi Im using image_submit_tag to submit my form. works fine.. but the > image is displayed with border. > > I used border => 0 but no use. > > This is my code. > > <%= image_submit_tag "../images/upload.png", :border => 0 %> > > any ideas?? > > Regards, > Srikanth > -- > 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. > > -- Thanks: Rajeev sharma -- 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.