[Rails] how to create local subroutines properly in rails?
hi guys, Using breadcrumbs on rails (http://github.com/weppos/ breadcrumbs_on_rails), I have added a method, set_breadcrumb in my application controller. That will set up my home breadcrumb. In my other feedbacks controller, I have the same set_breadcrumb method (in a before_filter). The breadcrumb added here is called feedback. the problem is that when the app runs and I load http://myapp:3000/feedback, I get feedback feedback as the breadcrumb. What's happened is that rails got confused and is looking at the most local copy of the set_breadcrumb method. I think part of the solution is to use a self.set_breadcrumb but couldn't find more to read up on My question is, how do we localise a method in a controller such that when I call :before_filter in that controller, the local version is used, whilst when the application controller calls the same method, it uses the copy that is defined in the application_controller itself? 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.
[Rails] Complex associations
I am working on a project that has some complex table associations, and I am having a hard time declaring this association in a Model, and fear it can't be done. Here is an example of my issue... class StoreType ActiveRecord::Base; end class Store ActiveRecord::Base; end class Department ActiveRecord::Base; end class Product ActiveRecord::Base; end A StoreType has many stores and a Store has many Department. However, both Store and Department have many products. An product has the columns store_id and department_id which are mutually exclusive. This is because a Product may belong directly to a Department, or it may be a 'global' product that belongs directly to the Store. What I'd like to do is have an association in the StoreType model that would give me all products for that StoreType. Currently, I have set up the following associtations on StoreType: class StoreType ActiveRecord::Base has_many :stores has_many :departments, :through=:stores has_many :store_products, :through=:stores, :source=:products, :uniq = true has_many :department_products, :through=:departments, :source=:products, :uniq = true end This is using the Nested Has Many Through plugin to achieve the nested association (department_products). However, I'd like to have a generic 'products' association for StoreType that pulls a combination of the two product associations. I'd like to do this through an association instead of just through a function because I want to gain the dynamic methods created by has_many, specifically the collection.find(...) method so I can add more conditions to the collection. Is there a way to do this? Thanks in advance! Trish -- 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] Generating .mo with Rails 2.1.0
Hello all, I'm a newbie to Ruby/Rails world, and also to the application I'm trying to use: Noosfero. The thing is, i'm trying to run 'rake makemo' with no success.. $/usr/bin/ruby1.8 -rconfig/boot -rgettext -rgettext/rails -rgettext/ utils -e 'GetText.create_mofiles(true, po, locale)' /usr/bin/ruby1.8: no such file to load -- gettext/rails (LoadError) Geminstalling gettext_rails doesn't help, maybe cause it is not for rails 2.1.0 Any help is appreciated. Regards, bráulio -- 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] Rails3-beta4: Calling to_json on an ActiveRecord::Relation causes an error
Here is my model and an attempt to convert to json. Whether there is data returned or not, a circular reference error is thrown. How can I avoid this? ruby-1.8.7-p249 PayPeriod = PayPeriod(id: integer, start_date: date, end_date: date, pay_date: date) ruby-1.8.7-p249 PayPeriod.where('end_date ?', Time.now) = [] ruby-1.8.7-p249 PayPeriod.where('end_date ?', Time.now).to_json ActiveSupport::JSON::Encoding::CircularReferenceError: object references itself from /Users/wprater/.rvm/gems/ruby-1.8.7-p249/gems/ activesupport-3.0.0.beta4/lib/active_support/json/encoding.rb:59:in `check_for_circular_references' -- 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 data as a transaction
Hey Everyone I'm new to RoR and this group so please let me know if I'm not being descriptive enough, or if I'm asking questions when I should RTFM. I have a basic understanding of RoR, but I'm kinda missing the next step for a web application I have in mind. I want to create an order form, where the user clicks on say New Form, and then enter name and address and other basic info. Then, using some AJAX he can add multiple items to the order. Now I think I understand how to do this if I want to create an Order, and then each time the user adds a new item that item gets put into the database, etc. What I can't figure out how to do is have the user fill out a form, and then submit it at the end to make sure nothing gets put into the db until the form is complete. I don't want the user changing their mind before clicking submit and being left with stale data in the db. And I would also like to do it as a transaction so that if the database fails I can roll back data. Now I'm sure this is possible...but I just don't know where I'm supposed to store the data until final submission time in Ruby. In PHP I would just use some session data to store data as the user is going through. Is that the Ruby Way too? Am I missing something? Any explanations, or pointers to some good reading are welcomed! Thanks! Joe -- 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] :url being ignored or routing problem?
background i have a page with a drop-down menu item. if any of the choices is selected, a partial gets activated to appear with new drop-down menu choices. the initial page uses a select_tag, observe_field, and a div to implement the above desired functionality. the pages i am working with comprise a sub/child area within an admin area. this all used to work, but for some reason stopped work at some unknown time. troubleshooting i'm looking at the log, and it seems to me that when i am at the initial page (and surrounding pages), i am in the desired controller. routing appears to be working as expected. however, when i test my drop-down menu, it appears as though 1) the :url = {:controller = .. details are being ignored; and 2) the parent admin controller only is getting processed rather than the supposed current admin/assets controller. it is as if the default, last route, map.connect ':controller/:action/:id' is being consulted rather than the :url in observe_field or anything else higher pertaining to admin and assets in routes. assets gets parsed as/demoted to an action rather than as part of the controller. %= select_tag(:type, options_for_select(['[select one]','page','program','event']), :id = 'type_selection') % %= observe_field('type_selection', :frequency = 0.5, :update = 'page_selection', :url = {:controller = admin/assets, :action = :set_pages}, :with = 'type='+$('type_selection').value) % div id=page_selection /div set_pages is defined as a method in the admin/assets controller. questions what (routing) is taking precedence? where is observe_field getting its instructions from instead, why does it seem as if its :url argument is being ignored? i've performed the usual basic tasks, such as restarting the application, etc. but obviously i'm missing something.. probably something very basic :/ please advise. -- 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] JOBS: Experienced Rails Developer
Over the last two years, Bonanzle has been amongst the fastest growing marketplaces in all of ecommerce. Since launching in late 2008, we have grown to nearly 2 million monthly visitors and more than 3 million items posted for sale. We are looking to continue our aggressive growth by adding all star talent to our small, Seattle- based team. As Bonanzle's Lead Ruby on Rails developer, you will work with the Product Lead and CEO to craft a code base that is modular and able to evolve quickly. Just as our company does. Our core company goal is to hire the best people possible, give them clear objectives, and let them flex their creative muscles without being micromanaged. We keep our processes to a minimum so you can keep your output at a maximum. Requirements * Three years experience coding web applications (at least half of which was spent using Rails) * Extremely strong coding skills, with talent that has proven itself through a continuous string of successful projects. * Ability to quickly digest, conceptualize and modify unfamiliar code. * Penchant for writing DRY, highly flexible, Rails code. * Deep familiarity with databases, preferably Mysql. Prefer experience working in databases of millions of records. * Worked in Linux two or more years. * Excellent command of written and spoken English, and permanent legal right to work in the U.S. * Experience in a startup environment: May involve work after normal business hours, and being on-call. * Ability to commute to the Seattle area. Benefits * Highly competitive salary * High performance Mac (or Ubuntu) machine with large LCD dual monitors * Free soft drinks and snacks * Comprehensive health insurance * Stock options plan * Flextime * Paid vacation * Performance bonuses * Paid trips to relevant developer events -- 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] Rails3-beta4: Calling to_json on an ActiveRecord::Relation causes an error
On Mon, Aug 2, 2010 at 2:26 PM, wprater mc.willpra...@gmail.com wrote: Here is my model and an attempt to convert to json. Whether there is data returned or not, a circular reference error is thrown. How can I avoid this? wprater, I would recommend trying Rails 3 RC by doing the following: gem install rails --pre Also, if you don't have a requirement to use Ruby 1.8.7, I would recommend using Ruby 1.9.2 RC2 by doing the following: rvm install 1.9.2 Ryan Bates recently added the following screencast which covers the installation of both Rails 3 and Ruby 1.9.2. http://media.railscasts.com/videos/225_upgrading_to_rails_3_part_1.mov Good luck, -Conrad ruby-1.8.7-p249 PayPeriod = PayPeriod(id: integer, start_date: date, end_date: date, pay_date: date) ruby-1.8.7-p249 PayPeriod.where('end_date ?', Time.now) = [] ruby-1.8.7-p249 PayPeriod.where('end_date ?', Time.now).to_json ActiveSupport::JSON::Encoding::CircularReferenceError: object references itself from /Users/wprater/.rvm/gems/ruby-1.8.7-p249/gems/ activesupport-3.0.0.beta4/lib/active_support/json/encoding.rb:59:in `check_for_circular_references' -- 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.comrubyonrails-talk%2bunsubscr...@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: The Future OF RUBY and RUBY ON RAILS
Dave gets +1 awesome on the missing the java boat point. Same deal here. Ruby is a great language. Rails is a great framework. There's no rule that says that this technology CAN'T go away, but the trend with Ruby/Rails has been explosive growth for the last five years or so. I've personally been working with it for three years, and just got offered a job today as a Rails developer. From a business/career perspective, I advocate technology agnosticism as far as what you can work with - David Kahn's points about taking TDD, DRY, ORM and other concepts into new languages/ stacks holds very very true. However, you're totally welcome in IT to have preferences. Some people prefer Microsoft over *nix/open source. Some prefer Cisco over Brocade. Some one might prefer shoulda over Test::Unit. Neither is necessarily right or wrong - they all have their place. Knowing when to use which technology platform and how to implement it is the key. Rails is a tool in the tool box. Nothing more. Nothing less. Learn to use various tools for various jobs. For web applications development, Rails just happens to be the best tool I've found for the job. But maybe some one prefers the grip of merb or sinatra better - no problem! The point isn't so much about which is the one true faith so-to-speak, but about knowing the strengths and weaknesses of all of them, and the proper business and technical use cases for each. From a career growth/job availability perspective, let me just tell you this: I'm basically what you'd call a mid level developer. I'm 28, been working as a web applications developer for 9 years this winter, have no *formal* training in OOP methodologies or design. I put my resume up on dice.com as a searchable resume only three weeks ago. My phone has been ringing with NEW calls from recruiters all over the United States to the tune of anywhere from 3 to 10 different jobs being thrown at me as potentials every day. And that's only looking at Washington DC, Denver, CO and Austin, TX. In spite of targeting those places, I'm getting calls from recruiters in San Francisco, LA, New York, and others as well. On Thursday of last week I interviewed for a position. It was offered in writing today (Monday). Less than a week from interview to offer, and I'll probably start next week (still nailing down a few details). That's my personal experience with RoR as a career choice for technology platform :) There DEFINITELY is growth in the Ruby/Rails space, and a lot of very large, important platforms are built on an RoR stack. My personal prediction is that this technology will be around for a while. It's going to take a decade or more to rival the popularity of .NET or Java, if it ever does (and I don't think it ever will, lacking major corporate backing like Sun/Oracle or Microsoft), but I see it becoming as popular as PHP/Drupal and similar stacks in the future. On Aug 2, 9:07 am, Dave Aronson googlegroups2d...@davearonson.com wrote: On Mon, Aug 2, 2010 at 01:15, Musdev Musdev li...@ruby-forum.com wrote: DO you guys see Ruby and Ruby on Rails sticking around for a while? and do you see an increase in demand for ruby/ruby on rails developers? I definitely see an increase over the past several years. Pretty much can't help it with something new, unless it sucks horribly (and doesn't have huge marketing muscle or government requirements behind it). Will it stick around, is another question. Another framework could some along that would make RoR look horrible by comparison. Rails 3 could suck horribly. (Though even then, we'd still have Rails 2 to use.) My crystal ball is in the shop. I'm sure hoping it sticks around, though. I kinda missed the boat with Java -- learned it in about 1998 or so, but didn't row hard enough to get much work in it. Now it seems like 95% of the openings are in Java, but I don't have the several years of experience most of them demand, while kids who will work for half my salary are coming out of school with at least solid training. I don't want to miss the boat with Ruby, either by my not rowing hard enough to catch it, or by it sinking. (I'll dispense with the obvious Khayyam pun.) -Dave -- Specialization is for insects. -RAH | Have Pun, Will Babble! -me Programming Blog:http://codosaur.us| Work:http://davearonson.com Leadership Blog: http://dare2xl.com| Play:http://davearonson.net * * * * * WATCH THIS SPACE * * * * * | Ruby:http://mars.groupsite.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] Complex associations
class Store ActiveRecord::Base has_many: store_type has_many: product_type, :through = department class Department ActiveRecord::Base belongs_to: store belongs_to: product class Product ActiveRecord::Base has_many :departments has_many :stores, :through = department end I think you need to remove the StoreType as a model... On Mon, Aug 2, 2010 at 11:05 AM, Trish trish.b...@gmail.com wrote: I am working on a project that has some complex table associations, and I am having a hard time declaring this association in a Model, and fear it can't be done. Here is an example of my issue... class StoreType ActiveRecord::Base; end class Store ActiveRecord::Base; end class Department ActiveRecord::Base; end class Product ActiveRecord::Base; end A StoreType has many stores and a Store has many Department. However, both Store and Department have many products. An product has the columns store_id and department_id which are mutually exclusive. This is because a Product may belong directly to a Department, or it may be a 'global' product that belongs directly to the Store. What I'd like to do is have an association in the StoreType model that would give me all products for that StoreType. Currently, I have set up the following associtations on StoreType: class StoreType ActiveRecord::Base has_many :stores has_many :departments, :through=:stores has_many :store_products, :through=:stores, :source=:products, :uniq = true has_many :department_products, :through=:departments, :source=:products, :uniq = true end This is using the Nested Has Many Through plugin to achieve the nested association (department_products). However, I'd like to have a generic 'products' association for StoreType that pulls a combination of the two product associations. I'd like to do this through an association instead of just through a function because I want to gain the dynamic methods created by has_many, specifically the collection.find(...) method so I can add more conditions to the collection. Is there a way to do this? Thanks in advance! Trish -- 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.comrubyonrails-talk%2bunsubscr...@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.
Re: [Rails] Generating .mo with Rails 2.1.0
Already fixed... just removed the unecessary option -rgettext/rails from command line 2010/8/2 Bráulio Bhavamitra brauli...@gmail.com Hello all, I'm a newbie to Ruby/Rails world, and also to the application I'm trying to use: Noosfero. The thing is, i'm trying to run 'rake makemo' with no success.. $/usr/bin/ruby1.8 -rconfig/boot -rgettext -rgettext/rails -rgettext/ utils -e 'GetText.create_mofiles(true, po, locale)' /usr/bin/ruby1.8: no such file to load -- gettext/rails (LoadError) Geminstalling gettext_rails doesn't help, maybe cause it is not for rails 2.1.0 Any help is appreciated. Regards, bráulio -- 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.comrubyonrails-talk%2bunsubscr...@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] SystemExit: exit
ActionView::TemplateError (SystemExit: exit: SELECT * FROM product_stocklevels WHERE (product_stocklevels.product_id = 831 AND (size = 'W44 L 32' AND stock 0)) LIMIT 1) Before I paste more code, has anyone come across this before? -- 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: how to configure rails to use mysql by default (not sqlite3)
just add -d mysql option when you create a new rails project -- 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: :url being ignored or routing problem?
On Aug 2, 11:15 pm, suzuki elle.on.ra...@gmail.com wrote: troubleshooting i'm looking at the log, and it seems to me that when i am at the initial page (and surrounding pages), i am in the desired controller. routing appears to be working as expected. however, when i test my drop-down menu, it appears as though 1) the :url = {:controller = .. details are being ignored; and 2) the parent admin controller only is getting processed rather than the supposed current admin/assets controller. it is as if the default, last route, map.connect ':controller/:action/:id' is being consulted rather than the :url in observe_field or anything else higher pertaining to admin and assets in routes. assets gets parsed as/demoted to an action rather than as part of the controller. %= select_tag(:type, options_for_select(['[select one]','page','program','event']), :id = 'type_selection') % %= observe_field('type_selection', :frequency = 0.5, :update = 'page_selection', :url = {:controller = admin/assets, :action = :set_pages}, :with = 'type='+$('type_selection').value) % div id=page_selection /div What is in the rendered html? Fred -- 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-beta4: Calling to_json on an ActiveRecord::Relation causes an error
Hi All, I have had this problem with Rails 3 and 1.9.1. The fix for this error is to add to_a to the json call. render :json = {:top = @top.to_a.as_json(:only = [:id, :title ] ) } Hope this helps. Huet On Aug 3, 8:01 am, Conrad Taylor conra...@gmail.com wrote: On Mon, Aug 2, 2010 at 2:26 PM, wprater mc.willpra...@gmail.com wrote: Here is my model and an attempt to convert to json. Whether there is data returned or not, a circular reference error is thrown. How can I avoid this? wprater, I would recommend trying Rails 3 RC by doing the following: gem install rails --pre Also, if you don't have a requirement to use Ruby 1.8.7, I would recommend using Ruby 1.9.2 RC2 by doing the following: rvm install 1.9.2 Ryan Bates recently added the following screencast which covers the installation of both Rails 3 and Ruby 1.9.2. http://media.railscasts.com/videos/225_upgrading_to_rails_3_part_1.mov Good luck, -Conrad ruby-1.8.7-p249 PayPeriod = PayPeriod(id: integer, start_date: date, end_date: date, pay_date: date) ruby-1.8.7-p249 PayPeriod.where('end_date ?', Time.now) = [] ruby-1.8.7-p249 PayPeriod.where('end_date ?', Time.now).to_json ActiveSupport::JSON::Encoding::CircularReferenceError: object references itself from /Users/wprater/.rvm/gems/ruby-1.8.7-p249/gems/ activesupport-3.0.0.beta4/lib/active_support/json/encoding.rb:59:in `check_for_circular_references' -- 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.comrubyonrails-talk%2bunsubscr...@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: File creation in Rails
To access files in rails, you can use the Ruby File Class http://ruby-doc.org/core/classes/File.html#M002579 You can put this into a method in the model. Then either call it specifically from the controller, or use an after_update callback to automatically create the file after the object has been saved to the database def save_file(filename) File.open #{RAILS_ROOT}/tmp/#{filename}, 'w' do |f| f.write contents end end Tonypm -- 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] Drop down box in ruby
Hello I've only been playing with ruby and rails for a few short weeks, I have an class called time in my libs folder and I want to call an array from this class and populate a drop down box/select box in rails in one of my view pages. everything online is so confusing regarding this.. Just say my array is like this time = [[minute,min,20,50],[hour,hr,10,50]] How would I get a select box to list -minute -second Also where is the most correct places to put the method to call the array in the rails application? I would really appreciate someone helping me learn 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: Drop down box in ruby
How would I get a select box to list -minute -hour -- 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: Drop down box in ruby
i didn't understand that... try to explain me some things... i would be pleased to help. so, you want a ComboBox that shows what? the values in the array? if it is so, you may want to populate this array in the controller, and iterate it in the view, adding values for each item in your array. imagine this: I have an array of places, that i want to show in a ComboBox in the view. so, in the controller you create an instance variable, thats your array, and in the view, you`ll put pure HTML and iterate your array adding values like: form select name=hour %...@my_array.each do |h| % option value=%= h.value %%= h.text % %end% /select /form you understand what I mean? by doing this, rails will use the injected ruby code to iterate trough your form, and will repeat the same code for each item in the array, remember you can work this out... well... lets try to solve your problem... lets say you have this array @time = [[minute,min,20,50],[hour,hr,10,50]] then in the view you'll iterate this array: form select % @time.each do |item| % option value=%= item[1] %%= item[0] % % end % /select /form this way you'll have a ComboBox that shows whatever is in your array's item's 0 index, with the value (what goes with the form) being whatever is in you array's item's 1 index. I hope I'm being helpful... Lucas Franceschi Equipe de Programação (Automação) SGI Sistemas (049) 9922-3360 On Tue, Aug 3, 2010 at 8:10 AM, Chad Weier li...@ruby-forum.com wrote: How would I get a select box to list -minute -hour -- 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.comrubyonrails-talk%2bunsubscr...@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] ActiveRecord - find MySQL connection/thread ID for query
Hi, Is it possible, when using a find method with a Model, to record the MySQL thread ID for the subsequent database query? Does ActiveRecord expose this? Many thanks, Michaël -- 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: ActiveRecord - find MySQL connection/thread ID for query
Michaël wrote: Hi, Is it possible, when using a find method with a Model, to record the MySQL thread ID for the subsequent database query? Does ActiveRecord expose this? Why on earth would you need this? What are you trying to achieve? Many thanks, Micha�l 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 data as a transaction
On 2 August 2010 22:48, pipplo joe.kos...@gmail.com wrote: Hey Everyone I'm new to RoR and this group so please let me know if I'm not being descriptive enough, or if I'm asking questions when I should RTFM. I have a basic understanding of RoR, but I'm kinda missing the next step for a web application I have in mind. I want to create an order form, where the user clicks on say New Form, and then enter name and address and other basic info. Then, using some AJAX he can add multiple items to the order. Now I think I understand how to do this if I want to create an Order, and then each time the user adds a new item that item gets put into the database, etc. What I can't figure out how to do is have the user fill out a form, and then submit it at the end to make sure nothing gets put into the db until the form is complete. I don't want the user changing their mind before clicking submit and being left with stale data in the db. And I would also like to do it as a transaction so that if the database fails I can roll back data. Now I'm sure this is possible...but I just don't know where I'm supposed to store the data until final submission time in Ruby. In PHP I would just use some session data to store data as the user is going through. Is that the Ruby Way too? Am I missing something? Using the session is a reasonable way to go. I wonder whether you need to store anything in the db till all is complete, you could just keep it in the session. Then you don't have to worry about clearing it up if the operation is never completed. Colin Any explanations, or pointers to some good reading are welcomed! Thanks! Joe -- 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: [ANN] NullDB 0.0.1
Avdi Grimm wrote: == What NullDB is a Rails database connection adapter that interprets common database operations as no-ops. It is the Null Object pattern as applied to database adapters. [...] == Why NullDB is intended to assist in writing fast database-independant unit tests for ActiveRecord classes. For why you would want to test your models without the database, see: http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database. I'm not at all convinced that this is a good way of testing (and in my experience, ThoughtWorks' software has lots of problems, which could say something about their testing practices). However, assuming for the moment that it is good... [...] * It is *not* an in-memory database. Finds will not work. Neither will #reload, currently. So how is this of any use at all? Normally, when I use tests with database operations, I do so to confirm that I'm writing to the database what I think I am. (Sure, I could use RSpec's mocks to test that -- and then I wouldn't need NullDB in the first place.) By removing the capability to save records, it seems to me that you've removed any utility that this might have had. Am I missing something? How do *you* find this puppy useful? 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: ActiveRecord - find MySQL connection/thread ID for query
On Aug 3, 1:24 pm, Marnen Laibow-Koser li...@ruby-forum.com wrote: Michaël wrote: Hi, Is it possible, when using a find method with a Model, to record the MySQL thread ID for the subsequent database query? Does ActiveRecord expose this? Why on earth would you need this? What are you trying to achieve? Many thanks, Micha l Because the application I'm maintaining uses Model find() methods to run large queries on the database to produce reports. These queries can take upwards of 10 minutes due to some complex table joins. While I'm altering the way these are working so they're not taking a large amount of time, I need an interim solution where I monitor the database for any of these queries that are taking more than a set maximum time, killing the thread of those queries that are going over the threshold and recording which query was killed so it can be re-run at a quieter time. It would be really useful if, when one of these large finds is run, that I could record the thread ID it creates so if I need to kill a thread, I can match it back up to the originating find() call. -- 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] Returning last value
Hi. I have the following controller of the update action: [code] def update @projeto = Projeto.find(params[:id]) if (@projeto.update_attributes(params[:projeto])) ## Mesmo raciocínio utilizado no create. @permissaoA = Permissao.find(:first, :conditions = [usuario_id = ?, @projeto.responsavel.to_i]) @permissaoAvancado1 = Permissao.find(:first, :conditions = [projeto_id = ? and usuario_id = ?, 0, @projeto.responsavel.to_i]) if @permissaoAvancado1.nil? ## Caso tenham excluido os usuários responsáveis, as permissões seriam nulas. Dai ele verifica se vai alterar ou criar uma permissão if @permissaoA.nil? @permissaoAv = Permissao.new(params[:permissao]) @permissaoAv.perfil = Avançado @permissaoAv.usuario = Usuario.find(:first, :conditions = [id = ?, @projeto.responsavel.to_i]) @permissaoAv.save(params[:permissao]) end end ## O mesmo que avançado @permissaoI = Permissao.find(:first, :conditions = [projeto_id = ? and perfil = ? and usuario_id = ?, @projeto.id, Intermediário, @projeto.responsavel_td.to_i]) @permissoesB = Permissao.all(:conditions = [projeto_id = ? and usuario_id = ? and perfil = ?, @projeto.id, @projeto.responsavel_td.to_i, Básico]) @permissaoAvancado2 = Permissao.find(:first, :conditions = [projeto_id = ? and usuario_id = ?, 0, @projeto.responsavel_td.to_i]) if @permissaoAvancado2.nil? if @permissaoI.nil? @permissaoIn = Permissao.new(params[:permissao]) #else # @permissaoIn = @permissaoI #end @permissaoIn.usuario = Usuario.find(:first, :conditions = [id = ?, @projeto.responsavel_td.to_i]) @permissaoIn.projeto = Projeto.find(:first, :conditions = [id = ?, @projeto.id]) @permissaoIn.perfil = Intermediário #if !...@permissaoi.nil? #@permissaoIn.update_attributes(params[:permissao]) #else @permissaoIn.save(params[:permissao]) if !...@permissoesb.empty? for perm in @permissoesB perm.destroy end end end end @permissaoB = Permissao.find(:first, :conditions = [projeto_id = ? and perfil = ? and usuario_id = ?, @projeto.id, Básico, @projeto.coordenador.to_i]) @permissaoAvancado3 = Permissao.all(:conditions = [projeto_id = ? and usuario_id = ?, 0, @projeto.coordenador.to_i]) @permissoesI = Permissao.all(:conditions = [projeto_id = ? AND usuario_id = ? AND perfil = ?, @projeto.id, @projeto.coordenador.to_i, Intermediário]) ## Se ele já tiver a permissao de avançado, não faz nada. Se não tiver, cria uma (sem nenhum projeto) if @permissaoAvancado3.empty? @permissoesI.empty? #if @permissaoB.nil? @permissaoBa = Permissao.new(params[:permissao]) #else # @permissaoBa = @permissaoB #end @permissaoBa.usuario = Usuario.find(:first, :conditions = [id = ?, @projeto.coordenador.to_i]) @permissaoBa.projeto = Projeto.find(:first, :conditions = [id = ?, @projeto.id]) @permissaoBa.perfil = Básico #if !...@permissaob.nil? #@permissaoBa.update_attributes(params[:permissao]) #else @permissaoBa.save(params[:permissao]) #end end ## Ao editar um projeto, existe a possibilidade da alteração do responsável pela Td ## Portanto, ele procura por todas as tarefas daquele projeto @tarefas = Tarefa.all(:conditions = [projeto_id = ?, @projeto.id]) ## Varre cada uma for tarefa in @tarefas ## Altera o campo responsável pelo respnsável_td recém modificado (ou não) na edição do projeto tarefa.responsavel = Usuario.find(:first, :conditions = [id = ?, @projeto.responsavel_td]).nome ## Atualiza as alterações tarefa.update_attributes(params[:tarefa]) end flash[:msg] = Projeto atualizado com sucesso redirect_to(@projeto) else render :action = edit end end [/code] It works ok, but what i wanna do is: destroy the permissao of responsavel_td and coordenador BEFORE the update. in other words, if the responsavel_td or the coordenador change, i wanna to destroy the permissao existing for those who were before the change. I make my self clear? If you can't understand me, just think this way.. How can I return the value before the update? Thanks any help. -- 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] Languages
My client has a translator and wants a lot of his page content to be translated into 6 different languages. When a user selects their language on the front end, it need to alter the Page content, Page title and Navigation title. I've made alternate columns in my database for the other languages. Although it's messy, it is what the client requested. So I assume I'll need an action in my application controller to set session data and then render the appropriate content front-end. Now, can someone give me any help regarding this process, or has anyone come across this before? -- 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
Pale Horse wrote: My client has a translator and wants a lot of his page content to be translated into 6 different languages. When a user selects their language on the front end, it need to alter the Page content, Page title and Navigation title. I've made alternate columns in my database for the other languages. Although it's messy, it is what the client requested. So I assume I'll need an action in my application controller to set session data and then render the appropriate content front-end. Now, can someone give me any help regarding this process, or has anyone come across this before? First I have to ask if you have read the Rails Internationalization (I18n) guide: http://guides.rubyonrails.org/i18n.html Or is your question specifically related to how to store the user's preferred language. -- 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: Juggernaut Rails 3
Same thing for me, I plan to put online a site with juggernaut this fall, an I keep wondering if its the right gem for a chatting engine. Is there any other gem or libs more up to date? Rémi Kenneth wrote: Are there any plans to update the Juggernaut gem to be compatible with Rails 3? It doesn't seem to work as of now with Rails 3, unless I set up the whole thing wrong. Also are there any good working alternatives for a push server? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-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
Robert Walker wrote: Pale Horse wrote: My client has a translator and wants a lot of his page content to be translated into 6 different languages. When a user selects their language on the front end, it need to alter the Page content, Page title and Navigation title. I've made alternate columns in my database for the other languages. Although it's messy, it is what the client requested. So I assume I'll need an action in my application controller to set session data and then render the appropriate content front-end. Now, can someone give me any help regarding this process, or has anyone come across this before? First I have to ask if you have read the Rails Internationalization (I18n) guide: http://guides.rubyonrails.org/i18n.html I've not read this, though I imagine it to be overkill for my purposes. 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. -- 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: Rails 3: Update responding with empty json
Fabio Kreusch wrote: I am still stuck with this. Does anyone knows if this is the expected beavior for Rails? Should respond_with on update really return an empty json object? I pretty sure the Rails behavior is as intended. Rails basically says the save was successful by returning a 200 status code. jQuery however, considers the request successful if it gets a 200 status code AND some valid json content. Personally, I like the Rails way better here. But nonetheless, I'm currently stuck with the same problem. An ugly (but working!) solution would be to replace your respond_with with this render :json = { :ok = true } Did you find a nicer solution? -- 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: Languages
On Tue, Aug 3, 2010 at 11:06 AM, Pale Horse li...@ruby-forum.com wrote: Robert Walker wrote: Pale Horse wrote: My client has a translator and wants a lot of his page content to be translated into 6 different languages. When a user selects their language on the front end, it need to alter the Page content, Page title and Navigation title. I've made alternate columns in my database for the other languages. Although it's messy, it is what the client requested. So I assume I'll need an action in my application controller to set session data and then render the appropriate content front-end. Now, can someone give me any help regarding this process, or has anyone come across this before? First I have to ask if you have read the Rails Internationalization (I18n) guide: http://guides.rubyonrails.org/i18n.html 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 with i18n. 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. 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. 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. 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. -- Leonardo Mateo. There's no place like ~ -- 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: Complex associations
Thank you for your response. However, I am refactoring an existing application, and am trying to remove a bunch of pure SQL that was put in the code. I believe the best way to do this is with a table association. One of the big features I want to use out of this is retrieving the records in the proper order (I'd prefer not to sort with Ruby after the fact since that would force me to rewrite a bunch of code for the sorting of the report). However, as this is an existing application (similar in setup to the example I gave), I cannot remove the model, as there is a table already associated with it, and the ids are being used. Another option that would work is to use a 'joins' statement in my finder method so I can sort products based on Store attributes with something like this: FROM products LEFT JOIN departments on departements.id = products.department_id LEFT JOIN stores on stores.id = products.store_id OR stores.id = departments.store_id However, I am also using an :include option for several associations, and it seems that joins and include are mutually exclusive. I'd really had to have to write out all of the associations. Any thoughts? Thanks! Trish On Aug 3, 2:11 am, Angel Robert Marquez angel.marq...@gmail.com wrote: class Store ActiveRecord::Base has_many: store_type has_many: product_type, :through = department class Department ActiveRecord::Base belongs_to: store belongs_to: product class Product ActiveRecord::Base has_many :departments has_many :stores, :through = department end I think you need to remove the StoreType as a model... On Mon, Aug 2, 2010 at 11:05 AM, Trish trish.b...@gmail.com wrote: I am working on a project that has some complex table associations, and I am having a hard time declaring this association in a Model, and fear it can't be done. Here is an example of my issue... class StoreType ActiveRecord::Base; end class Store ActiveRecord::Base; end class Department ActiveRecord::Base; end class Product ActiveRecord::Base; end A StoreType has many stores and a Store has many Department. However, both Store and Department have many products. An product has the columns store_id and department_id which are mutually exclusive. This is because a Product may belong directly to a Department, or it may be a 'global' product that belongs directly to the Store. What I'd like to do is have an association in the StoreType model that would give me all products for that StoreType. Currently, I have set up the following associtations on StoreType: class StoreType ActiveRecord::Base has_many :stores has_many :departments, :through=:stores has_many :store_products, :through=:stores, :source=:products, :uniq = true has_many :department_products, :through=:departments, :source=:products, :uniq = true end This is using the Nested Has Many Through plugin to achieve the nested association (department_products). However, I'd like to have a generic 'products' association for StoreType that pulls a combination of the two product associations. I'd like to do this through an association instead of just through a function because I want to gain the dynamic methods created by has_many, specifically the collection.find(...) method so I can add more conditions to the collection. Is there a way to do this? Thanks in advance! Trish -- 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.comrubyonrails-talk%2Bunsubscrib e...@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: Drop down box in ruby
Chad Weier wrote: I have an class called time in my libs folder and I want to call an array from this class and populate a drop down box/select box in rails in one of my view pages. everything online is so confusing regarding this.. There are multiple ways of invoking the helpers to produce output. Just say my array is like this time = [[minute,min,20,50],[hour,hr,10,50]] Sorry but I do not understand. Obviously min is short for minute but how do 20 and 50 relate? And same for the hours? Whare are the values of those 'minute' and 'min' and 'hour' and 'hr' variables? How would I get a select box to list -minute -second But you don't even list minute or second in your time array. Let's try a simple example. Suppose you have a Time object and you want to set a variable 'value' to one of several values. %= select(:time, :value, { One = 1, Two = 2, Three = 3 }) % That will create html output: select id=time_value name=time[value] option value=One1/option option value=Two2/option option value=Three3/option /select That will display One, Two, and Three in the selection dropdown box. Upon POST submission this will create a params[:time] array containing :value as params[:time][:value] containing either 1, 2 or 3. Since it is part of the params[:time] object you can simply create a new Time in the controller normally. @time = Time.new(params[:time]) The variable 'value' will be assigned automatically to the object. I used one, two, three since those are illustrative of the technique. But you can do many other things there. And there is another helper called collection_select() that is also very useful when dealing with an array of objects. The values may also be nested arrays. But I think the previous is more visible and easier to read. But the following is also possible. %= select(:time, :value, [[One,1],[Two,2],[Three,3]]) % As to your particular issue: time = [[minute,min,20,50],[hour,hr,10,50]] Sorry but I do not understand this example. So instead let me assume that you have the following: time = { Hour = 3600, Minute = 60, Second = 1 } Then the following: %= select(:time, :value, time) % Will produce this HTML: select id=time_value name=time[value] option value=Hour3600/option option value=Minute60/option option value=Second1/option /select Hope this is helpful! 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: ActiveRecord - find MySQL connection/thread ID for query
Michaël wrote: On Aug 3, 1:24�pm, Marnen Laibow-Koser li...@ruby-forum.com wrote: Many thanks, Micha l [Please quote what you're replying to. It will make the discussion easier to follow.] Because the application I'm maintaining uses Model find() methods to run large queries on the database to produce reports. These queries can take upwards of 10 minutes due to some complex table joins. While I'm altering the way these are working so they're not taking a large amount of time, I need an interim solution where I monitor the database for any of these queries that are taking more than a set maximum time, killing the thread of those queries that are going over the threshold and recording which query was killed so it can be re-run at a quieter time. Your database should already do this. You don't need to do it from Rails. It would be really useful if, when one of these large finds is run, that I could record the thread ID it creates so if I need to kill a thread, I can match it back up to the originating find() call. If the database kills a thread, can't you just rescue the appropriate exception? 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: Re: Languages
Leonardo Mateo wrote: On Tue, Aug 3, 2010 at 11:06 AM, Pale Horse li...@ruby-forum.com 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 with i18n. 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. Rails I18N is not really nice. I recommend fast_gettext instead. 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 existing I18N 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-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: ActiveRecord - find MySQL connection/thread ID for query
It would be really useful if, when one of these large finds is run, that I could record the thread ID it creates so if I need to kill a thread, I can match it back up to the originating find() call. If the database kills a thread, can't you just rescue the appropriate exception? That's a good point. I'll try catching the exception and storing the find parameters so I can run that query at time when I can afford to. Thanks for the help, Michaël -- 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: Languages
Marnen Laibow-Koser wrote: Rails I18N is not really nice. I recommend fast_gettext instead. 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 existing I18N 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. How effective and accurate are the I18N translation solutions? More-so than members of the foreign-speaking countries themselves that my client is in contact with? -- 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 CSS
Hi, It's not specifically related to Rails, but how do you arrange your CSS files? I used to dump everything in a gigantic screen.css file. Then I noticed that some rules only appeared in a few pages. Therefore I am considering having a layout.css for all pages and roughly 1 css file per controller if I need specific things in it that are not found in layout.css. How do you organize that? -- 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: Languages
Pale Horse wrote: [...] How effective and accurate are the I18N translation solutions? More-so than members of the foreign-speaking countries themselves that my client is in contact with? The Rails I18N modules are not translation solutions. They're simply modules for managing the translated text. You still need a human translator to generate that translated text. 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: simple redirect_to shows in log but doesn't redirect
Have you tried naming the file create.js.rjs? On Aug 2, 11:46 am, Neil Bye li...@ruby-forum.com wrote: Joshua Mckinney wrote: From inside your create method in the controller, what does request.format return? If the request is a plain old html request is should put text/html If the request is an ajax request is should put text/javascript if the request puts text/html or anything besides text/javascript you can force the format by adding: request.format = :js to the controller method. If I try this def create �...@story = Story.find(params[:story_id]) �...@story.comments.create params[:comment] request.format = :js end or this def create �...@story = Story.find(params[:story_id]) �...@story.comments.create params[:comment] end both give Comment Create (0.5ms) INSERT INTO comments (created_at, body, updated_at, story_id) VALUES('2010-08-02 16:38:36', 'cat', '2010-08-02 16:38:36', 2) ActionView::MissingTemplate (Missing template comments/create.erb in view path app/views): Still can't see where it's going wrong. In peace Neil -- 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: Languages
Marnen Laibow-Koser wrote: Pale Horse wrote: [...] How effective and accurate are the I18N translation solutions? More-so than members of the foreign-speaking countries themselves that my client is in contact with? The Rails I18N modules are not translation solutions. They're simply modules for managing the translated text. You still need a human translator to generate that translated text. Best, -- Marnen Laibow-koser http://www.marnen.org mar...@marnen.org Thank you. I'll investigate that now. -- 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: How to CSS
Fernando Perez wrote: Hi, It's not specifically related to Rails, but how do you arrange your CSS files? I used to dump everything in a gigantic screen.css file. Then I noticed that some rules only appeared in a few pages. Therefore I am considering having a layout.css for all pages and roughly 1 css file per controller if I need specific things in it that are not found in layout.css. How do you organize that? The latter way. I also *highly* recommend using Sass: CSS alone is not powerful enough to fully separate content from presentation in a maintainable way -- Sass' higher-level abstractions are necessary here. 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: Re: Languages
Pale Horse wrote: Marnen Laibow-Koser wrote: Pale Horse wrote: [...] How effective and accurate are the I18N translation solutions? More-so than members of the foreign-speaking countries themselves that my client is in contact with? The Rails I18N modules are not translation solutions. They're simply modules for managing the translated text. You still need a human translator to generate that translated text. Best, -- Marnen Laibow-koser http://www.marnen.org mar...@marnen.org Thank you. I'll investigate that now. Actually, I think some of the Rails I18N stuff may have translations of common Rails boilerplate ({{model}} could not be saved because of the following errors), but for anything nonstandard, my point stands. 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: Complex associations
Thank you for your response. However, I am refactoring an existing application, and am trying to remove a bunch of pure SQL that was put in the code. I believe the best way to do this is with a table association. Why do you believe this? One of the big features I want to use out of this is retrieving the records in the proper order (I'd prefer not to sort with Ruby after the fact since that would force me to rewrite a bunch of code for the sorting of the report). What is the proper order? However, as this is an existing application (similar in setup to the example I gave), I cannot remove the model, as there is a table already associated with it, and the ids are being used. Gotcha. Another option that would work is to use a 'joins' statement in my finder method so I can sort products based on Store attributes with something like this: FROM products LEFT JOIN departments on departements.id = products.department_id LEFT JOIN stores on stores.id = products.store_id OR stores.id = departments.store_id why not SELECT view INNER JOIN associations WHERE = AND = OR =. However, I am also using an :include option for several associations, and it seems that joins and include are mutually exclusive. I'd really had to have to write out all of the associations. I'll respond after I unravel what that means in my head. Any thoughts? Those are my thoughts. I'm newish and find attempting to help in turn helps me to learn. I hope you don't mind. Thanks! You are welcome Trish Angel On Aug 3, 2:11 am, Angel Robert Marquez angel.marq...@gmail.com wrote: class Store ActiveRecord::Base has_many: store_type has_many: product_type, :through = department class Department ActiveRecord::Base belongs_to: store belongs_to: product class Product ActiveRecord::Base has_many :departments has_many :stores, :through = department end I think you need to remove the StoreType as a model... On Mon, Aug 2, 2010 at 11:05 AM, Trish trish.b...@gmail.com wrote: I am working on a project that has some complex table associations, and I am having a hard time declaring this association in a Model, and fear it can't be done. Here is an example of my issue... class StoreType ActiveRecord::Base; end class Store ActiveRecord::Base; end class Department ActiveRecord::Base; end class Product ActiveRecord::Base; end A StoreType has many stores and a Store has many Department. However, both Store and Department have many products. An product has the columns store_id and department_id which are mutually exclusive. This is because a Product may belong directly to a Department, or it may be a 'global' product that belongs directly to the Store. What I'd like to do is have an association in the StoreType model that would give me all products for that StoreType. Currently, I have set up the following associtations on StoreType: class StoreType ActiveRecord::Base has_many :stores has_many :departments, :through=:stores has_many :store_products, :through=:stores, :source=:products, :uniq = true has_many :department_products, :through=:departments, :source=:products, :uniq = true end This is using the Nested Has Many Through plugin to achieve the nested association (department_products). However, I'd like to have a generic 'products' association for StoreType that pulls a combination of the two product associations. I'd like to do this through an association instead of just through a function because I want to gain the dynamic methods created by has_many, specifically the collection.find(...) method so I can add more conditions to the collection. Is there a way to do this? Thanks in advance! Trish -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com . To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.comrubyonrails-talk%2bunsubscr...@googlegroups.comrubyonrails-talk%2Bunsubscrib e...@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.comrubyonrails-talk%2bunsubscr...@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
[Rails] Re: how to configure rails to use mysql by default (not sqlite3)
Olivier Db wrote: Hello, I am running Mac OS X 10.6.4 and have installed the following: ruby-1.9.1-p429 (64 bits, I believe!) RubyGems 1.3.7 Rails 2.3.8 MySQL 5.1.49 (64 bits) I am now getting an error because sqlite3 is not installed SQLite comes with Mac OS. The OS uses it internally. No installation should be necessary, though you will probably have to install the sqlite3 gem. and I've read that there are issues installing ruby-sqlite3! Not to my knowledge. SO I'm not sure if I should (or how to) install sqlite3. A developer suggested I use sqlite3 for testing and mysql for production, but wouldn't that mean having to convert my sqlite database to mysql for production? No. You have separate databases. You've also got migrations. No conversion is required. I might just as well always use mysql, no? It depends. On the one hand, it's extremely convenient and fast to use SQLite for testing and development. On the other hand, you may find that you would rather have the same DB in development as production. I've done it both ways. Both are fine. (And I would say you might as well *never* use MySQL. PostgreSQL is a much, much better DB.) Which leads me to the following question: how do I configure rails to always default to using mysql database instead of sqlite3? -d mysql Thank you for your help. Best regards, Olivier 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: Complex associations
See below... Thanks! Trish On Aug 3, 11:00 am, Angel Robert Marquez angel.marq...@gmail.com wrote: Thank you for your response. However, I am refactoring an existing application, and am trying to remove a bunch of pure SQL that was put in the code. I believe the best way to do this is with a table association. Why do you believe this? This seems to be the best way to retrieve the needed data in the proper order. My closest attempt gets me two sets of data (for department_products and store_products), and then I do a find on their ids, allowing me to do the :order statement as needed. One of the big features I want to use out of this is retrieving the records in the proper order (I'd prefer not to sort with Ruby after the fact since that would force me to rewrite a bunch of code for the sorting of the report). What is the proper order? This report needs to have (and currently has) multi-column sort capabilities However, as this is an existing application (similar in setup to the example I gave), I cannot remove the model, as there is a table already associated with it, and the ids are being used. Gotcha. Another option that would work is to use a 'joins' statement in my finder method so I can sort products based on Store attributes with something like this: FROM products LEFT JOIN departments on departements.id = products.department_id LEFT JOIN stores on stores.id = products.store_id OR stores.id = departments.store_id why not SELECT view INNER JOIN associations WHERE = AND = OR =. forgive my SQL... that is just an attempt to explain what I need. SQL is definitely not my strong suit. However, I am also using an :include option for several associations, and it seems that joins and include are mutually exclusive. I'd really had to have to write out all of the associations. I'll respond after I unravel what that means in my head. I suppose what this all comes down to, is a way to achieve the necessary SQL through ActiveRecord so I can properly determine the table.column_names to sort on. As I mentioned earlier, I am able to get the needed product items with my doing a find on the sum of ids... so I guess this is less of an association issue, and more of a joins issue ActiveRecord.find so I can get my proper sorting order.. Any thoughts? Those are my thoughts. I'm newish and find attempting to help in turn helps me to learn. I hope you don't mind. Any advise helps! I appreciate your taking the time to think about this. Thanks! You are welcome Trish Angel On Aug 3, 2:11 am, Angel Robert Marquez angel.marq...@gmail.com wrote: class Store ActiveRecord::Base has_many: store_type has_many: product_type, :through = department class Department ActiveRecord::Base belongs_to: store belongs_to: product class Product ActiveRecord::Base has_many :departments has_many :stores, :through = department end I think you need to remove the StoreType as a model... On Mon, Aug 2, 2010 at 11:05 AM, Trish trish.b...@gmail.com wrote: I am working on a project that has some complex table associations, and I am having a hard time declaring this association in a Model, and fear it can't be done. Here is an example of my issue... class StoreType ActiveRecord::Base; end class Store ActiveRecord::Base; end class Department ActiveRecord::Base; end class Product ActiveRecord::Base; end A StoreType has many stores and a Store has many Department. However, both Store and Department have many products. An product has the columns store_id and department_id which are mutually exclusive. This is because a Product may belong directly to a Department, or it may be a 'global' product that belongs directly to the Store. What I'd like to do is have an association in the StoreType model that would give me all products for that StoreType. Currently, I have set up the following associtations on StoreType: class StoreType ActiveRecord::Base has_many :stores has_many :departments, :through=:stores has_many :store_products, :through=:stores, :source=:products, :uniq = true has_many :department_products, :through=:departments, :source=:products, :uniq = true end This is using the Nested Has Many Through plugin to achieve the nested association (department_products). However, I'd like to have a generic 'products' association for StoreType that pulls a combination of the two product associations. I'd like to do this through an association instead of just through a function because I want to gain the dynamic methods created by has_many, specifically the collection.find(...) method so I can add more conditions to the collection. Is there a way to do this? Thanks in advance! Trish -- You received this message because you are subscribed to
[Rails] Re: How to CSS
How do you organize that? The latter way. Ok. I also *highly* recommend using Sass: CSS alone is not powerful enough to fully separate content from presentation in a maintainable way -- Sass' higher-level abstractions are necessary here. I find sass ugly, and I reviewed less, but in the end I stayed with pure css. -- 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: simple redirect_to shows in log but doesn't redirect
Joshua Mckinney wrote: Have you tried naming the file create.js.rjs? Good idea but no difference. The latest configuration of the create function is: def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] request.format = :js end Gives a page with the address http://localhost:3000/stories/2/comments it should be http://localhost:3000/stories/2/ and it says this. Template is missing Missing template comments/create.erb in view path app/views Even if I make create.html.erb or as it asks create.erb it makes no difference. Does that shed any light on the problem? In peace Neil -- 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 CSS
On Tue, Aug 3, 2010 at 12:42 PM, Fernando Perez li...@ruby-forum.com wrote: How do you organize that? The latter way. Ok. Also, take a look at http://www.alistapart.com/articles/progressiveenhancementwithcss. The article recommends ways for splitting up your CSS. I also *highly* recommend using Sass: CSS alone is not powerful enough to fully separate content from presentation in a maintainable way -- Sass' higher-level abstractions are necessary here. I find sass ugly, and I reviewed less, but in the end I stayed with pure css. -- 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: How to CSS
Fernando Perez wrote: How do you organize that? The latter way. Ok. I also *highly* recommend using Sass: CSS alone is not powerful enough to fully separate content from presentation in a maintainable way -- Sass' higher-level abstractions are necessary here. I find sass ugly, and I reviewed less, but in the end I stayed with pure css. That is a bad idea. You should learn Sass well enough to be able to use it to clean up your markup. If you're using plain CSS, you're working too hard. I've noticed that you tend to disparage tools outside a fairly narrow comfort zone, even when those tools could materially help you. May I suggest broadening your horizons a bit? 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] rails 2.3.8 and html_safe
Hi, Can somebody update me on the state of html_safe strings in rails 2.3.8? I know rails 2.3.6 and 2.3.7 broke a lot of code because strings were being escaped when they shouldn't have been and I thought this was all fixed in 2.3.8. I'm upgrading an app from 2.3.5 to 2.3.8 and there are many spots where previous code was output correctly and now it expects html_safe method calls to properly escape the strings. Are those who don't want to use the new escaping behaviour in the 2.3.x branch expected to stick with 2.3.5 from now on moving forward? Thanks, Andrew -- 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: simple redirect_to shows in log but doesn't redirect
Latest development. I've changed the ajax call stories/show.html.erb to div id='aremark' %= render :partial = 'comment' % /div h5label for=loginMake a comment:/label/h5 % remote_form_for :comment, :update ='aremark', :url=story_comments_path(@story) do |form| % div id=body%= form.text_field :body %/div p%= submit_tag 'Comment' %/p It still creates the comment in the database. It correctly returns to http://localhost:3000/stories/2 It even updates the 'aremark' div But it fills it with Template is missing Missing template comments/create.erb in view path app/views Any ideas? Excuse me while I bang my head on a wall. In peace Neil -- 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: [ANN] NullDB 0.0.1
Marnen Laibow-Koser wrote: Avdi Grimm wrote: == What NullDB is a Rails database connection adapter that interprets common database operations as no-ops. It is the Null Object pattern as applied to database adapters. [...] == Why NullDB is intended to assist in writing fast database-independant unit tests for ActiveRecord classes. For why you would want to test your models without the database, see: http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database. I'm not at all convinced that this is a good way of testing (and in my experience, ThoughtWorks' software has lots of problems, which could say something about their testing practices). However, assuming for the moment that it is good... [...] * It is *not* an in-memory database. Finds will not work. Neither will #reload, currently. So how is this of any use at all? Normally, when I use tests with database operations, I do so to confirm that I'm writing to the database what I think I am. (Sure, I could use RSpec's mocks to test that -- and then I wouldn't need NullDB in the first place.) By removing the capability to save records, it seems to me that you've removed any utility that this might have had. Am I missing something? How do *you* find this puppy useful? Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org Sent from my iPhone Marnen, I'm fairly new to unit testing and TDD, but I think I understand the concept of what they're talking about here. The point is that if you are writing to the database during unit tests, you're actually testing the database adapter and abstraction layer, in this case: ActiveRecord, and not the logic that you have written. ActiveRecord, has been tested extensively, it would be redundant to test it again. By removing the database from the testing, you can focus on testing your business logic... and you have the side benefit of it being quicker, which is essential for TDD to be a practical way to develop software. I think what you're describing is considered to be functional testing or integration test, not unit testing. Functional and integration testing is equally important, it just occurs at a different level. This is one of the *rare* times when I think Ruby got it wrong when compared with other languages, most other more mature languages Java, C++, etc.. provide tools to avoid hitting the database during unit testing for just this reason. I think Rails, and Ruby in general is heading in this direction too. The next generation of ORM databases like DataMapper have this sort of thing built in. Hope this helps! Cheers, Eric -- 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] PDFKit Fork() Function Unimplemented Error - HELP!
Hello All, We're working on a project on a Windows machine that will use PDFKit to convert an HTML page to a PDF. I have followed all the instructions at GitHub (http://github.com/jdpace/PDFKit), for installing wkhtmltopdf and PDFKit, then creating the config file in 'config/initializers/pdfkit.rb' and then finally, setting up Middleware for Rails apps in 'config/environment.rb'. We have done all of the following and when we run the server and append the '.pdf' extension, we receive a 500 Internal Server Error. Upon inspection of the console, we find a fork() function unimplemented error. The console output is listed below: --- /!\ FAILSAFE /!\ Tue Aug 03 08:28:19 -0700 2010 Status: 500 Internal Server Error fork() function is unimplemented on this machine C:/Ruby186/lib/ruby/gems/1.8/gems/pdfkit-0.4.3/lib/pdfkit/pdfkit.rb:60:in `open' C:/Ruby186/lib/ruby/gems/1.8/gems/pdfkit-0.4.3/lib/pdfkit/pdfkit.rb:60:in `to_pdf' C:/Ruby186/lib/ruby/gems/1.8/gems/pdfkit-0.4.3/lib/pdfkit/middleware.rb:23:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/string_coercion.rb:25:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/head.rb:9:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/methodoverride.rb:24:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/params_parser.rb:15:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/session/cookie_store.rb:99:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/failsafe.rb:26:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/lock.rb:11:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/lock.rb:11:in `synchronize' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/lock.rb:11:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:114:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/reloader.rb:34:in `run' C:/Ruby186/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/dispatcher.rb:108:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/rack/static.rb:31:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/urlmap.rb:47:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/urlmap.rb:41:in `each' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/urlmap.rb:41:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/rack/log_tailer.rb:17:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/content_length.rb:13:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/chunked.rb:15:in `call' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/handler/mongrel.rb:67:in `process' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:159:in `process_client' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:158:in `each' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:158:in `process_client' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:285:in `run' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:285:in `initialize' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:285:in `new' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:285:in `run' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:268:in `initialize' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:268:in `new' C:/Ruby186/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mingw32/lib/mongrel.rb:268:in `run' C:/Ruby186/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/handler/mongrel.rb:38:in `run' C:/Ruby186/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/commands/server.rb:111 C:/Ruby186/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' C:/Ruby186/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' ./script/server:3 -e:2:in `load' -e:2 If anyone could help us get around this problem to be able to convert an HTML page to pdf, we would greatly appreciate it. Thanks in advance, -dwmcc -- 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] rendering multiline Javascript by using JSONP in rails
Hello everybody, In a controller I try to render a javascript google ad to print it into some HTML using JSONP, like this script type=text/javascript!-- google_ad_client = pub-23222424; google_alternate_color = FF; google_ad_width = 468; google_ad_height = 60; //--/script script type=text/javascript src=http://pagead2.google.com/pgad/show_ads.js; /script So I do: render :text var s_response = { content: 'script type=\text/ javascript\!--\\ngoogle_ad_client = \pub-23222424\;\ \ngoogle_alternate_color = \FF\;\\ngoogle_ad_width = 468;\ \ngoogle_ad_height = 60;\\n//--\\/script\\nscript type=\text/ javascript\\\n src=\http://pagead2.google.com/pgad/show_ads.js\;\ \n\\/script', id: '2'}; But i get this error: unterminated string literal [Break on this error] var response = { content: 'script type=text/ javascript!-- = That seems like it is a multilines problem right ? But I don't know how to resolve it. Thanks, Lucas -- 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: [ANN] NullDB 0.0.1
I'm fairly new to unit testing and TDD, but I think I understand the concept of what they're talking about here. The point is that if you are writing to the database during unit tests, you're actually testing the database adapter and abstraction layer, in this case: ActiveRecord, and not the logic that you have written. ActiveRecord, has been tested extensively, it would be redundant to test it again. By removing the database from the testing, you can focus on testing your business logic... and you have the side benefit of it being quicker, which is essential for TDD to be a practical way to develop software. I think what you're describing is considered to be functional testing or integration test, not unit testing. Functional and integration testing is equally important, it just occurs at a different level. This is one of the *rare* times when I think Ruby got it wrong when compared with other languages, most other more mature languages Java, C++, etc.. provide tools to avoid hitting the database during unit testing for just this reason. I think Rails, and Ruby in general is heading in this direction too. The next generation of ORM databases like DataMapper have this sort of thing built in. Hope this helps! Cheers, Eric Oh, and I almost forgot to mention that Factory_Girl does this as well. Using Factory.build() you only write to memory and not the database. Factory_Girl can also allow writing to the database for functional and integration testing, so you get the best of both worlds. It's one of the pieces in my testing suite. -Eric -- 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: [ANN] NullDB 0.0.1
Eric Schmitt wrote: Marnen, I'm fairly new to unit testing and TDD, I've been doing test-first development as long as I've been doing Rails development, nearly 3 years. (Whether that means that I too am new to unit testing is left as an exercise for the student.) ? but I think I understand the concept of what they're talking about here. The point is that if you are writing to the database during unit tests, you're actually testing the database adapter and abstraction layer, in this case: ActiveRecord, and not the logic that you have written. That is commonly believed, but the situation is IMHO not that open-and-shut. Read on. ActiveRecord, has been tested extensively, it would be redundant to test it again. By removing the database from the testing, you can focus on testing your business logic... Not always. Often, removing the DB from testing makes it *harder* to focus on testing the logic. Some examples may be helpful here. Of course, it's asinine for me to do User.create! :name = 'John' User.find_by_name('John').should_not be_nil as that would indeed be testing ActiveRecord. But consider class Sandwich def make_blt Ingredient.create(:name = 'bacon') Ingredient.create(:name = 'lettuce') Ingredient.create(:name = 'tomato') end end I think it is entirely reasonable to test this with describe Sandwich describe 'make_blt' it should create bacon, lettuce, and tomato do Sandwich.make_blt ['bacon', 'lettuce', 'tomato'].each do |name| Ingredient.find_by_name(name).should_not be_nil end end end end because this is not testing ActiveRecord; rather, it's testing that I made the proper *calls* to ActiveRecord. To be sure, in this case, I could just as easily do Ingredient.should_receive(:create).with(:name = 'bacon'), but that's only possible because the method is so simple, and to my mind it's a little smelly anyway: since the method being tested should be treated as a black box, I'd rather verify the final state than chase all the method calls that got us there. And the only way to verify the final state is to have something tracking that state -- like, oh, say, a DB. and you have the side benefit of it being quicker, which is essential for TDD to be a practical way to develop software. An in-memory DB has similar benefits while not discarding state. I think what you're describing is considered to be functional testing or integration test, not unit testing. The test I wrote above would certainly be considered a unit test. [...] This is one of the *rare* times when I think Ruby got it wrong when compared with other languages, most other more mature languages Java, C++, etc.. provide tools to avoid hitting the database during unit testing for just this reason. This is a Rails and ActiveRecord issue, not a Ruby one. I think Rails, and Ruby in general is heading in this direction too. The next generation of ORM databases like DataMapper have this sort of thing built in. DataMapper is an ORM, not an ORM database. In what respect does DataMapper's testing differ here? (I've never used DataMapper, though it certainly looks interesting.) Hope this helps! Only by tending to confirm that some of the argument here is fallacious (unless Avdi has a better one). Cheers, Eric 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: rendering multiline Javascript by using JSONP in rails
Lucas wrote: Hello everybody, In a controller I try to render a javascript google ad to print it into some HTML using JSONP, like this script type=text/javascript!-- google_ad_client = pub-23222424; google_alternate_color = FF; google_ad_width = 468; google_ad_height = 60; //--/script script type=text/javascript src=http://pagead2.google.com/pgad/show_ads.js; /script So I do: render :text var s_response = { content: 'script type=\text/ javascript\!--\\ngoogle_ad_client = \pub-23222424\;\ \ngoogle_alternate_color = \FF\;\\ngoogle_ad_width = 468;\ \ngoogle_ad_height = 60;\\n//--\\/script\\nscript type=\text/ javascript\\\n src=\http://pagead2.google.com/pgad/show_ads.js\;\ \n\\/script', id: '2'}; But i get this error: unterminated string literal [Break on this error] var response = { content: 'script type=text/ javascript!-- = That seems like it is a multilines problem right ? No. The problem is that your double-quoted string contains double quotes! But I don't know how to resolve it. There are quoting constructs that would do the trick. But you have a bigger problem: you really shouldn't be doing this in the controller. Rendered JS, like rendered HTML, belongs in the view. Thanks, Lucas 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] Prevent Helper Automatically Escaping String
I'm writing a helper to generate the display of a product and its information as retrieved from the database. Several HTML tags are part of this. As I'm building the string I want included in the HTML, Rails is automatically escaping the string - which prevents me from actually using the string I build. gt;h2lt; is *NOT* the same as h2. How can I prevent Rails from doing 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] Restfull routes, link_to, and additional paramters
I am trying to do a link_to with multiple to create an object. Everything works until ad the second parameter in. As soon as I add the second parameter, it forgets to add any information about the first one. link_to create, foos_path(@foo, :bar_id = @bar.id), :method = :post What am I doing incorrect? -- 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] Prevent Helper Automatically Escaping String
I'm writing a helper to generate the display of a product and its information as retrieved from the database. Several HTML tags are part of this. As I'm building the string I want included in the HTML, Rails is automatically escaping the string - which prevents me from actually using the string I build. gt;h2lt; is *NOT* the same as h2. How can I prevent Rails from doing this? def my_helper h2my unsafe string/h2.html_safe! end See http://weblog.rubyonrails.org/2009/10/12/what-s-new-in-edge-rails -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.
[Rails] Re: [ANN] NullDB 0.0.1
Marnen, You make some interesting points... I think I still have a ton to learn about unit testing and TDD best practices. I'm still just getting started. Thanks for the info! Warmest Regards, Eric -- 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: rails 2.3.8 and html_safe
I just hit a similar problem where I was concatenating strings with escapable characters within a formbuilder. I googled about and there seems to be a some logic being discussed that anything that is magic security is going to be a nightmare. My problems were quite isolated (the great thing about form builders) What was: 'a id=' + field_name.to_s + '-help href=# class=tooltip title=' + help + '' Turned into 'a id='.html_safe + field_name.to_s + '-help href=# class=tooltip title='.html_safe + help + ''.html_safe I am sure there are other ways but this seemed the easiest for me for string concatenation. O. -- 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: Prevent Helper Automatically Escaping String
Philip Hallstrom wrote: def my_helper h2my unsafe string/h2.html_safe! end See http://weblog.rubyonrails.org/2009/10/12/what-s-new-in-edge-rails I'm not running edge rails, I'm running Rails 2.3.8. There is no html_safe! method defined, so this won't work. -- 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: simple redirect_to shows in log but doesn't redirect
The 2 most direct causes I can think of that would produce that error would be: 1. create.js.rjs is not in the correct director (.../app/views/ comments/create.js.rjs 2. create.js.rjs does not exist or bad file name Try using: def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] request.format = :js respond_to do |format| format.js end end Although respond _to blocks are not always necessary, it can't hurt to try. On Aug 3, 11:58 am, Neil Bye li...@ruby-forum.com wrote: Joshua Mckinney wrote: Have you tried naming the file create.js.rjs? Good idea but no difference. The latest configuration of the create function is: def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] request.format = :js end Gives a page with the addresshttp://localhost:3000/stories/2/comments it should behttp://localhost:3000/stories/2/and it says this. Template is missing Missing template comments/create.erb in view path app/views Even if I make create.html.erb or as it asks create.erb it makes no difference. Does that shed any light on the problem? In peace Neil -- 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.
Re: [Rails] Re: Prevent Helper Automatically Escaping String
def my_helper h2my unsafe string/h2.html_safe! end See http://weblog.rubyonrails.org/2009/10/12/what-s-new-in-edge-rails I'm not running edge rails, I'm running Rails 2.3.8. There is no html_safe! method defined, so this won't work. Ah. Then look at activesupport/lib/active_support/core_ext/string/output_safety.rb -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.
[Rails] Re: Prevent Helper Automatically Escaping String
Michael Satterwhite wrote: Philip Hallstrom wrote: def my_helper h2my unsafe string/h2.html_safe! end See http://weblog.rubyonrails.org/2009/10/12/what-s-new-in-edge-rails Or you can use the raw method in the view I think: %= raw my_helper % Sort of like the opposite of the old h method. I'm not running edge rails, I'm running Rails 2.3.8. There is no html_safe! method defined, so this won't work. If you're not running Rails 3, and did not install the plugin for Rails 2.3.x that does the automatic escaping they you are escaping it somewhere, maybe not realizing it. Are you sure you're not wrapping the result in an h method? -- 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: rendering multiline Javascript by using JSONP in rails
No. The problem is that your double-quoted string contains double quotes! It contains double-quotes but they are escaped aren't they ? There are quoting constructs that would do the trick. But you have a bigger problem: you really shouldn't be doing this in the controller. Rendered JS, like rendered HTML, belongs in the view. In fact this code isn't print in my HTML but in the HTML of another website, thiat is why it is in a controller and not a view Thanks, Lucas -- 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: Prevent Helper Automatically Escaping String
Philip Hallstrom wrote: Ah. Then look at activesupport/lib/active_support/core_ext/string/output_safety.rb OK, I'm looking at it. I must be dense, though - or I've got a BAD case of tunnel vision. How do I STOP these from changing the string? I'm sure it's obvious ... but I'm not seeing it. BTW: Thanks for pointing me at this. ---Michael -- 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: [ANN] NullDB 0.0.1
1. Why are we suddenly discussing a two year old post here? Clue me in. 2. Myron Marsten is now the maintainer of NullDB. See http://github.com/nulldb/nulldb 3. I'm not really interested in rehashing the arguments for NullDB. Enough teams are happily using it that I had to transfer maintainership over to someone else so that I could focus on other projects. I suggest you go on the RSpec-User's mailing list and ask if someone wants to explain why they use it. But briefly, I'll say this: if you are including the DB, you aren't Unit Testing. Period. Your tests might be *useful* and *important*, but they aren't Unit Tests. A lot of Rails practices, while overall encouraging more TDD, have muddied the waters WRT to what is a Unit Test. A Unit test isolates a *single* object or method from *all* of its collaborators, and tests the inputs of that object or method in a vacuum. If it doesn't isolate, it's not a Unit Test. Which, again, is not to say it's a bad test. These days I drive my app development almost exclusively from high-level full-stack Cucumber acceptance tests, and only drop down to the Unit level when there is some particularly interesting/tricky logic to be described. And sometimes I write functional level tests that include the DB but not the UI level. But I don't call them unit tests and I keep them separate from my unit tests. If you are interested in this kind of Unit Test discipline - which, when followed, tends to make for smaller, tightly-cohesive objects - NullDB may be for you. Especially because it enables you to test (for instance) logic in after_save hooks which would otherwise force the DB to get involved. -- Avdi -- 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: rails 2.3.8 and html_safe
Andrew Kaspick wrote: I'm upgrading an app from 2.3.5 to 2.3.8 and there are many spots where previous code was output correctly and now it expects html_safe method calls to properly escape the strings. Are those who don't want to use the new escaping behaviour in the 2.3.x branch expected to stick with 2.3.5 from now on moving forward? I haven't yet done the conversion of my 2.3.5 app to 2.3.8, will hopefully do so soon. I intend to do this as a first step in preparing it for Rails 3. However, as I understand it nothing should change in the escaping unless you install the rails_xss. In fact that was the problem with 2.3.6 2.3.7. Version 2.3.6 introduced a problem discovered by the HAML guys, and 2.3.7 was a hasty fix for that, which broken stuff for everyone else. Version 2.3.8 was supposed to get things back to normal. -- 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: Prevent Helper Automatically Escaping String
Robert Walker wrote: Michael Satterwhite wrote: Philip Hallstrom wrote: def my_helper h2my unsafe string/h2.html_safe! end See http://weblog.rubyonrails.org/2009/10/12/what-s-new-in-edge-rails Or you can use the raw method in the view I think: THANK YOU! THANK YOU! THANK YOU! This works. If you're not running Rails 3, and did not install the plugin for Rails 2.3.x that does the automatic escaping they you are escaping it somewhere, maybe not realizing it. I don't know of a plugin for that installed ... and I do the installing on this system. The ' h xxx was a good idea, but I wasn't doing it. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-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: Prevent Helper Automatically Escaping String
Michael Satterwhite wrote: Philip Hallstrom wrote: Ah. Then look at activesupport/lib/active_support/core_ext/string/output_safety.rb OK, I'm looking at it. I must be dense, though - or I've got a BAD case of tunnel vision. How do I STOP these from changing the string? I'm sure it's obvious ... but I'm not seeing it. BTW: Thanks for pointing me at this. ---Michael some_string = scriptalert(Gotcha!)/script %= h some_string % or %= html_escape some_string % = scriptalert(Gotcha!)/script %= some_string % = [[ javascript alert dialog = Gotcha! ]] -- 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: rails 2.3.8 and html_safe
Robert Walker wrote: Andrew Kaspick wrote: I'm upgrading an app from 2.3.5 to 2.3.8 and there are many spots where previous code was output correctly and now it expects html_safe method calls to properly escape the strings. Are those who don't want to use the new escaping behaviour in the 2.3.x branch expected to stick with 2.3.5 from now on moving forward? I haven't yet done the conversion of my 2.3.5 app to 2.3.8, will hopefully do so soon. I intend to do this as a first step in preparing it for Rails 3. However, as I understand it nothing should change in the escaping unless you install the rails_xss. In fact that was the problem with 2.3.6 2.3.7. Version 2.3.6 introduced a problem discovered by the HAML guys, and 2.3.7 was a hasty fix for that, which broken stuff for everyone else. Version 2.3.8 was supposed to get things back to normal. Exactly. I'm not using the rails_xss plugin, but the escaping rules are not as they were in 2.3.5. String literals were safe in 2.3.5, but aren't in 2.3.8... a minor difference with huge implications. I was looking at hacking the rails code to fix this for my local app, but wasn't sure why this would even still be a problem for 2.3.8 when this release was supposed to fix the fiasco that was 2.3.6 and 2.3.7. -- 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: segmentation fault from mysql_adapter.rb
Divya Mohan wrote: Not yet solved. :( I had a simular problem (i am also newbie) for me it was solved by adding host: localhost in the config/database.yml file Hope it can help some others to.. grtz, patrick -- 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] Strange error message when rendering the scaffold form
Hello everyone, I am developing my application and I created a scaffold called listas, but when I acess /listas/new I get this error message: NoMethodError in Listas#new Showing /home/rodrigo3n/code/listeiroo/app/views/listas/_form.html.erb where line #15 raised: undefined method `deep_symbolize_keys' for nil:NilClass Extracted source (around line #15): 12: % end % 13: 14: div class=field 15: %= f.label :nome %br / 16: %= f.text_field :nome % 17: /div 18: div class=field Trace of template inclusion: app/views/listas/new.html.erb I am using Rails 3RC and Ruby 1.9.2-rc2. This error is very strange to me because I did just create the scaffold via % rails g scaffold and then this error appeared. Do you know why? Thanks, Rodrigo Alves Vieira -- 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: Prevent Helper Automatically Escaping String
Robert Walker wrote: some_string = scriptalert(Gotcha!)/script Ignore my still syntax error above with the nested double quotes. Single quote the string in the JS part or fix however you like. %= h some_string % or %= html_escape some_string % = scriptalert(Gotcha!)/script %= some_string % = [[ javascript alert dialog = Gotcha! ]] Well, this is quite interesting. The above actually DID NOT work under Rails 2.3.8 for me. Same code escaped properly, and as expected, running under Rails 2.3.5. In my test the JS dialog was display whether h was used or not. Not good... Maybe on second though I'll skip Rails 2.3.8 altogether and go straight to Rails 3.0. -- 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: [ANN] NullDB 0.0.1
Avdi Grimm wrote: 1. Why are we suddenly discussing a two year old post here? Clue me in. My apologies! It appeared at the top of my list feed and I neglected to check the date. I'm not sure why it appeared at the top of my feed. [...] But briefly, I'll say this: if you are including the DB, you aren't Unit Testing. Period. Your tests might be *useful* and *important*, but they aren't Unit Tests. A lot of Rails practices, while overall encouraging more TDD, have muddied the waters WRT to what is a Unit Test. Yeah, I'm aware of that. A Unit test isolates a *single* object or method from *all* of its collaborators, and tests the inputs of that object or method in a vacuum. If it doesn't isolate, it's not a Unit Test. And there's an argument to be made that since the AR framework is part of an AR class, it must be respected -- and hit *some* state-preserving DB-like thing -- to properly unit test an AR class. Which, again, is not to say it's a bad test. These days I drive my app development almost exclusively from high-level full-stack Cucumber acceptance tests, and only drop down to the Unit level when there is some particularly interesting/tricky logic to be described. I do similarly. And sometimes I write functional level tests that include the DB but not the UI level. But I don't call them unit tests and I keep them separate from my unit tests. If you are interested in this kind of Unit Test discipline - which, when followed, tends to make for smaller, tightly-cohesive objects - NullDB may be for you. Got some sample code in this style? I'd like to look at it, even though I think (a priori) that it is a recklessly dangerous way to test AR classes. I just might learn something. :) Especially because it enables you to test (for instance) logic in after_save hooks which would otherwise force the DB to get involved. I *want* the DB to get involved if I'm testing the DB lifecycle of my objects. -- Avdi 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: rails 2.3.8 and html_safe
Andrew Kaspick wrote: Exactly. I'm not using the rails_xss plugin, but the escaping rules are not as they were in 2.3.5. String literals were safe in 2.3.5, but aren't in 2.3.8... a minor difference with huge implications. I created a quick-n-dirty test app. See the result here: http://www.ruby-forum.com/topic/214314#new -- 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: rendering multiline Javascript by using JSONP in rails
Lucas wrote: No. �The problem is that your double-quoted string contains double quotes! It contains double-quotes but they are escaped aren't they ? Whoops! You're right. I somehow overlooked the backslashes. There are quoting constructs that would do the trick. �But you have a bigger problem: you really shouldn't be doing this in the controller. Rendered JS, like rendered HTML, belongs in the view. In fact this code isn't print in my HTML but in the HTML of another website, thiat is why it is in a controller and not a view Doesn't matter. If it goes to the user's browser, it should generally be in a view. Thanks, Lucas 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: SystemExit: exit
Pale Horse wrote: ActionView::TemplateError (SystemExit: exit: SELECT * FROM product_stocklevels WHERE (product_stocklevels.product_id = 831 AND (size = 'W44 L 32' AND stock 0)) LIMIT 1) Before I paste more code, has anyone come across this before? Maybe you need to paste more code. Only think we can tell from this is that you have a TemplateError in your view. Most likely a syntax error somewhere. -- 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: rails 2.3.8 and html_safe
Robert Walker wrote: Andrew Kaspick wrote: Exactly. I'm not using the rails_xss plugin, but the escaping rules are not as they were in 2.3.5. String literals were safe in 2.3.5, but aren't in 2.3.8... a minor difference with huge implications. I created a quick-n-dirty test app. See the result here: http://www.ruby-forum.com/topic/214314#new 2.3.8 should not require the use of raw to do what worked out of the box in 2.3.5 and every release before that if rails_xss is not installed. 2.3.8 .html_safe? = false That result right there is why raw would be required now in 2.3.8 and not in 2.3.5. String literals in 2.3.8 should not be false... in rails 3 though that is correct and the expected result. -- 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: [ANN] NullDB 0.0.1
Marnen Laibow-Koser wrote: And there's an argument to be made that since the AR framework is part of an AR class, it must be respected -- and hit *some* state-preserving DB-like thing -- to properly unit test an AR class. This is the kind of muddling of concepts that I think Rails encourages. The idea that Model == Database Thingy. At every opportunity I encourage developers to start their apps with bare, pure Ruby models and only add ActiveRecord::Base in a later iteration. This practice helps to start thinking of your objects purely in terms of how they model your domain - which is how OO is supposed to work. After you spend some time looking at the models strictly in terms of their capabilities and responsibilities, then you add in persistence. Usually this means that you add a collaborator, which is some kind of OO/RDB mapping system. But it's still just another collaborator, with neat, clean division of responsibilities. Of course, AR makes it harder to think of it as a collaborator because you have to inherit from it and it adds all sorts of methods to self and imposes arbitrary rules like no initializers. But if you are careful you can still think of it as a (rather pushy) collaborator and structure your tests accordingly - separating the tests of persistence from the tests of logic. I'll add a post about the how and the why and the benefits of this kind of strict separation to my queue on Virtuous Code. -- Avdi -- 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: InvalidToken for a Flash upload
Lily ^_^ wrote: Hi, I am developping a small Flash app to upload multiple files with a progress bar in a Rails site. Rails handles the server side. I have a controller that displays the view containing the flash, and it also provides a security token to the flash. The Flash gets it and send it back to the server in the HTTP request that contains the file to upload. Big surprise : it works perfectly in Internet Explorer... but not in Firefox nor in Opera. :S For Firefox and Opera, I get a ActionController::InvalidAuthenticityToken in the console. I display the token in text in the console, in the view html and in the flash, and the token doesn't seem to be altered (though I had to CGI.escape the token to get it right in Flash, and escape it again in Flash to send it back, just because of the + that the token can contains). This is what the console shows for Firefox : Token from controller = ayZ/bR7r2W3qg61NIspeOsU0N/VBqHqjWamkRtQG+s4= ←[4;36;1mSQL (0.0ms)←[0m ←[0;1mSET SQL_AUTO_IS_NULL=0←[0m Processing UploadController#form (for 127.0.0.1 at 2010-08-01 13:12:25) [GET] Rendering upload/form Completed in 11ms (View: 9, DB: 0) | 200 OK [http://localhost/] ←[4;35;1mSQL (0.0ms)←[0m ←[0mSET SQL_AUTO_IS_NULL=0←[0m Processing UploadController#index (for 127.0.0.1 at 2010-08-01 13:12:29) [POST] Parameters: {Filename=Screenshot-14.jpg, authenticity_token=ayZ/bR7r2 W3qg61NIspeOsU0N/VBqHqjWamkRtQG+s4=, Upload=Submit Query, Filedata=#File:C:/Users/Lily/AppData/Local/Temp/RackMultipart.4856.0} ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticit yToken): And now for Internet Explorer : Token from controller = i1irXTa0JqlbBNTlfcRwFYdQ24L8yhTBQFWESSrSEZg= g==] ←[4;35;1mSQL (0.0ms)←[0m ←[0mSET SQL_AUTO_IS_NULL=0←[0m Processing UploadController#form (for 127.0.0.1 at 2010-08-01 13:15:02) [GET] Rendering upload/form Completed in 4ms (View: 2, DB: 0) | 200 OK [http://localhost/] ost/] ←[4;36;1mSQL (0.0ms)←[0m ←[0;1mSET SQL_AUTO_IS_NULL=0←[0m Processing UploadController#index (for 127.0.0.1 at 2010-08-01 13:15:19) [POST] Parameters: {Filename=MobilePhone_Icon.jpg, authenticity_token=i1irXT a0JqlbBNTlfcRwFYdQ24L8yhTBQFWESSrSEZg=, Upload=Submit Query, Filedata=#File:C:/Users/Lily/AppData/Local/Temp/RackMultipart.4 856.2} Completed in 8ms (View: 1, DB: 0) | 200 OK [http://localhost/upload?authenticity _token=i1irXTa0JqlbBNTlfcRwFYdQ24L8yhTBQFWESSrSEZg=] Could someone help me about this ? I searched quite a while on the net for an explaination; I found some people fix for Swfupload and Uploadify/Paperclip but couldn't get a solution out of it. (I'm using Rails 2.3.5 and Ruby 1.8.6 on this project, the Flash application is in ActionScript 3 compiled for the player 10) Still searching for a solution, if anyone could help. I really searched the web and found some tips but I still couldn't find out a solution. The upload stills work with IE and not with other browser. I read somewhere that it could be a problem of session id and tried this fix that supposed to override the middleware. But I don't think I understand what my Flash should eventually send to work... require 'rack/utils' class FlashSessionCookieMiddleware def initialize(app, session_key = '_session_id') @app = app @session_key = session_key end def call(env) if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/ puts * yeaaahh I'm in the condition ! puts * Session key is : + @session_key.to_s + and @app : + @app.to_s params = ::Rack::Utils.parse_query(env['QUERY_STRING']) env['HTTP_COOKIE'] = [ @session_key, params['session_key'] ].join('=').freeze unless params['session_key'].nil? end @app.call(env) end end By the way, this fix doesn't change that IE works anyway, and not FF nor Opera... -- 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: [ANN] NullDB 0.0.1
Avdi Grimm wrote: Marnen Laibow-Koser wrote: And there's an argument to be made that since the AR framework is part of an AR class, it must be respected -- and hit *some* state-preserving DB-like thing -- to properly unit test an AR class. This is the kind of muddling of concepts that I think Rails encourages. The idea that Model == Database Thingy. That's not an idea that I have. I used to do MVC without an ORM (and indeed, without official objects), and I'm quite used to writing non-AR models in Rails. At every opportunity I encourage developers to start their apps with bare, pure Ruby models and only add ActiveRecord::Base in a later iteration. That seems like more trouble than it's worth with Rails, but I'll think about how I'd try that. This practice helps to start thinking of your objects purely in terms of how they model your domain - which is how OO is supposed to work. No argument there. [...] Of course, AR makes it harder to think of it as a collaborator because you have to inherit from it and it adds all sorts of methods to self and imposes arbitrary rules like no initializers. But if you are careful you can still think of it as a (rather pushy) collaborator and structure your tests accordingly - separating the tests of persistence from the tests of logic. Again, I do that anyway. But if I'm testing features that touch the persistence layer, then I want an actual persistence layer to talk to, not just a black hole. And the way Rails structures its objects, I think that's still a unit test. If Rails worked a bit differently and used a separate persistence library instead of an ORM, then I'd agree with you on the appropriate way to test AR objects. But it doesn't, so I think I don't. I'll add a post about the how and the why and the benefits of this kind of strict separation to my queue on Virtuous Code. I will be interested to read that. At the moment, this separation just seems like fighting Rails to no advantage and some potential harm. -- Avdi 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: Strange error message when rendering the scaffold form
On Aug 3, 2:14 pm, rodrigo3n rodrig...@gmail.com wrote: Hello everyone, I am developing my application and I created a scaffold called listas, but when I acess /listas/new I get this error message: NoMethodError in Listas#new Showing /home/rodrigo3n/code/listeiroo/app/views/listas/_form.html.erb where line #15 raised: undefined method `deep_symbolize_keys' for nil:NilClass Extracted source (around line #15): 12: % end % 13: 14: div class=field 15: %= f.label :nome %br / 16: %= f.text_field :nome % 17: /div 18: div class=field Trace of template inclusion: app/views/listas/new.html.erb I am using Rails 3RC and Ruby 1.9.2-rc2. This error is very strange to me because I did just create the scaffold via % rails g scaffold and then this error appeared. Do you know why? Did you migrate the database? Jeff purpleworkshops.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] Returning last value
On 3 August 2010 14:17, Bla ... li...@ruby-forum.com wrote: Hi. I have the following controller of the update action: [code] def update �...@projeto = Projeto.find(params[:id]) if (@projeto.update_attributes(params[:projeto])) ## Mesmo raciocínio utilizado no create. �...@permissaoa = Permissao.find(:first, :conditions = [usuario_id = ?, @projeto.responsavel.to_i]) �...@permissaoavancado1 = Permissao.find(:first, :conditions = [projeto_id = ? and usuario_id = ?, 0, @projeto.responsavel.to_i]) if @permissaoAvancado1.nil? ## Caso tenham excluido os usuários responsáveis, as permissões seriam nulas. Dai ele verifica se vai alterar ou criar uma permissão if @permissaoA.nil? �...@permissaoav = Permissao.new(params[:permissao]) �...@permissaoav.perfil = Avançado �...@permissaoav.usuario = Usuario.find(:first, :conditions = [id = ?, @projeto.responsavel.to_i]) �...@permissaoav.save(params[:permissao]) end end ## O mesmo que avançado �...@permissaoi = Permissao.find(:first, :conditions = [projeto_id = ? and perfil = ? and usuario_id = ?, @projeto.id, Intermediário, @projeto.responsavel_td.to_i]) �...@permissoesb = Permissao.all(:conditions = [projeto_id = ? and usuario_id = ? and perfil = ?, @projeto.id, @projeto.responsavel_td.to_i, Básico]) �...@permissaoavancado2 = Permissao.find(:first, :conditions = [projeto_id = ? and usuario_id = ?, 0, @projeto.responsavel_td.to_i]) if @permissaoAvancado2.nil? if @permissaoI.nil? �...@permissaoin = Permissao.new(params[:permissao]) # else # �...@permissaoin = @permissaoI # end �...@permissaoin.usuario = Usuario.find(:first, :conditions = [id = ?, @projeto.responsavel_td.to_i]) �...@permissaoin.projeto = Projeto.find(:first, :conditions = [id = ?, @projeto.id]) �...@permissaoin.perfil = Intermediário # if !...@permissaoi.nil? # �...@permissaoin.update_attributes(params[:permissao]) # else �...@permissaoin.save(params[:permissao]) if !...@permissoesb.empty? for perm in @permissoesB perm.destroy end end end end �...@permissaob = Permissao.find(:first, :conditions = [projeto_id = ? and perfil = ? and usuario_id = ?, @projeto.id, Básico, @projeto.coordenador.to_i]) �...@permissaoavancado3 = Permissao.all(:conditions = [projeto_id = ? and usuario_id = ?, 0, @projeto.coordenador.to_i]) �...@permissoesi = Permissao.all(:conditions = [projeto_id = ? AND usuario_id = ? AND perfil = ?, @projeto.id, @projeto.coordenador.to_i, Intermediário]) ## Se ele já tiver a permissao de avançado, não faz nada. Se não tiver, cria uma (sem nenhum projeto) if @permissaoAvancado3.empty? @permissoesI.empty? # if @permissaoB.nil? �...@permissaoba = Permissao.new(params[:permissao]) # else # �...@permissaoba = @permissaoB # end �...@permissaoba.usuario = Usuario.find(:first, :conditions = [id = ?, @projeto.coordenador.to_i]) �...@permissaoba.projeto = Projeto.find(:first, :conditions = [id = ?, @projeto.id]) �...@permissaoba.perfil = Básico # if !...@permissaob.nil? # �...@permissaoba.update_attributes(params[:permissao]) # else �...@permissaoba.save(params[:permissao]) # end end ## Ao editar um projeto, existe a possibilidade da alteração do responsável pela Td ## Portanto, ele procura por todas as tarefas daquele projeto �...@tarefas = Tarefa.all(:conditions = [projeto_id = ?, @projeto.id]) ## Varre cada uma for tarefa in @tarefas ## Altera o campo responsável pelo respnsável_td recém modificado (ou não) na edição do projeto tarefa.responsavel = Usuario.find(:first, :conditions = [id = ?, @projeto.responsavel_td]).nome ## Atualiza as alterações tarefa.update_attributes(params[:tarefa]) end flash[:msg] = Projeto atualizado com sucesso redirect_to(@projeto) else render :action = edit end end [/code] It works ok, but what i wanna do is: destroy the permissao of responsavel_td and coordenador BEFORE the update. in other words, if the responsavel_td or the coordenador change, i wanna to destroy the permissao existing for those who were before the change. I make my self clear? No, not to me anyway, the code and question are too complex. Try to reduce your question to to it's basic requirement. Explain what you want to do simply rather than providing large amounts of (mostly) irrelevant code that would take too much time for the reader to understand. If you can't understand me, just think this way.. How can I return the value before the update? That is a much simpler question, but does not make sense as a standalone question 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
[Rails] Re: rails 2.3.8 and html_safe
Andrew Kaspick wrote: Robert Walker wrote: Andrew Kaspick wrote: Exactly. I'm not using the rails_xss plugin, but the escaping rules are not as they were in 2.3.5. String literals were safe in 2.3.5, but aren't in 2.3.8... a minor difference with huge implications. I created a quick-n-dirty test app. See the result here: http://www.ruby-forum.com/topic/214314#new 2.3.8 should not require the use of raw to do what worked out of the box in 2.3.5 and every release before that if rails_xss is not installed. 2.3.8 .html_safe? = false That result right there is why raw would be required now in 2.3.8 and not in 2.3.5. String literals in 2.3.8 should not be false... in rails 3 though that is correct and the expected result. There are other changes in 2.3.8 that are the cause of the escaping issues, but at the moment my app is not upgradeable to 2.3.8. I just wanted to know if others are having this issue, and it sounds like people are, but I'm still not sure if this is a bug or if this is the expected behviour for 2.3.8. If this is expected behaviour for 2.3.8 then this should not have been in a minor point release and instead saved for a 2.4 release or something. Quite disappointing. -- 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: simple redirect_to shows in log but doesn't redirect
Joshua Mckinney wrote: Try using: def create @story = Story.find(params[:story_id]) @story.comments.create params[:comment] request.format = :js respond_to do |format| format.js end end Although respond _to blocks are not always necessary, it can't hurt to try. Too bad, that gives ActionView::MissingTemplate (Missing template comments/create.erb in view path app/views): app/controllers/comments_controller.rb:13:in `create' Line 13 is respond_to do |format| So I took it out. create.js.rjs is in views/comments right I think. In peace Neil -- 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] rails 3 download - where ?
I'm trying to update my rails from 2.3.8 to 3.0, where can I get the kit from ? Thanks, Dani -- 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] rails 3 download - where ?
gem install rails --pre this will install rails 3.0 rc1 All the best, Fidel. On 8/3/10, Dani Dani li...@ruby-forum.com wrote: I'm trying to update my rails from 2.3.8 to 3.0, where can I get the kit from ? Thanks, Dani -- 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.
Re: [Rails] rails 3 download - where ?
Ryan Bates from railscasts.com has an excellent screencast on this subject. The links you are looking for are on the page under resources. http://railscasts.com/episodes/225-upgrading-to-rails-3-part-1 On Tue, Aug 3, 2010 at 4:04 PM, Dani Dani li...@ruby-forum.com wrote: I'm trying to update my rails from 2.3.8 to 3.0, where can I get the kit from ? Thanks, Dani -- 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.comrubyonrails-talk%2bunsubscr...@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] Rails3 + rcov
I hit a wall today with rcov + Rails3. I am developing my Rails3 app using Ruby 1.9.2-preview3. rcov and relevance-rcov do not work with Ruby 1.9.2 yet. I can't find any fork of rcov that does yet either. It wasn't that big of a deal since I could easily switch over to Ruby 1.8.7 using rvm --default 1.8.7; rake test:coverage. So then today I brought my app forward from beta4 to Rails 3.0.0-rc. That version requires linecache19. The problem is linecache19 doesn't compile with 1.8.7, only 1.9.2-preview3, it can't see my vm_core.h file no matter how I configure it's --include-* params. That means I lost my working rcov on my Ruby 1.8.7 setup and I now only have a barely working rcov with my 1.9.2-preview3 setup, and it creates terribly wrong coverage stats. What's my short-term solution for a working, accurate rcov? -- 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.
[Rails] Re: Restfull routes, link_to, and additional paramters
Jonathan Steel wrote: I am trying to do a link_to with multiple to create an object. Everything works until ad the second parameter in. As soon as I add the second parameter, it forgets to add any information about the first one. What do you mean, it forgets to add any information about the first one? I don't understand what you are trying to say there. link_to create, foos_path(@foo, :bar_id = @bar.id), :method = :post What am I doing incorrect? You are aware that links should be GET requests and not POST requests, right? GETs should be safe. http://www.w3.org/2001/tag/doc/whenToUseGet.html Also you should think about Progressive Enhancement and what happens when people do not have have Javascript available. Using :method requires Javascript to create a form on the fly in memory. It is just a normal GET otherwise. But as to your problem, I am not sure. It works for me. I just jigged up a test case of your example and I was able to use that same syntax just fine. I suggest enclosing the link_to with parenthesis. That can sometimes enable the error to be more visible with a different ruby message. %= link_to(create, foos_path(@foo, :bar_id = @bar.id), :method = :post) % Not sure but a shot in the dark. Make sure the parameter is a string with to_s. %= link_to(create, foos_path(@foo, :bar_id = @bar.id.to_s), :method = :post) % Are you including default Javascript libraries? IIRC that is needed. Not sure though. %= javascript_include_tag :defaults % Good luck! 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: rails 2.3.8 and html_safe
Andrew Kaspick wrote: I just wanted to know if others are having this issue, and it sounds like people are, but I'm still not sure if this is a bug or if this is the expected behviour for 2.3.8. If this is expected behaviour for 2.3.8 then this should not have been in a minor point release and instead saved for a 2.4 release or something. Quite disappointing. I don't know, but my quick test was really quite simple and certainly didn't present the behavior I would have expected from a Rails 2.3.x application: welcome_helper def gotcha_helper content_tag(:script, alert('Gotcha!')) end index.html.erb %= h gotcha_helper % Generated HTML - Rails 2.3.8 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en lang=en head meta http-equiv=Content-Type content=text/html; charset=utf-8/ titleuntitled/title /head body scriptalert('Gotcha!')/script /body /html Obviously not escaping is being done here and I see a JS alert dialog. Rails 2.3.5 HTML (in question) lt;scriptgt;alert('Gotcha!')lt;/scriptgt; All else being equal I'd call this a bug, but that's just me. Maybe I'm missing something obvious. -- 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] Rails 2.3.8 and form_tag usage
I have just upgraded my entire system to use the subject line version of rails...of course...this broke my previous rails apps as many things are handled a bit differently...! I have all apps running fine now but am having a problem when using form_tag over form_for...(I need form_tag so I can use 'select' drop- downs and can find no such usage for form-for)... Here's the error I get: Unknown action No action responded to 8. Actions: create, destroy, edit, index, new, show, and update Here's the form code: % form_tag :action = 'update', :id = @tankticket do % %= render :partial = 'form' % %= submit_tag 'Update' % % end % Here's the update code: def update @tankticket = Tankticket.find(params[:id]) respond_to do |format| if @tankticket.update_attributes(params[:tankticket]) format.html { redirect_to(@tankticket, :notice = 'Tankticket was successfully updated.') } format.xml { head :ok } else format.html { render :action = edit } format.xml { render :xml = @tankticket.errors, :status = :unprocessable_entity } end end end It's gotta be something simple that I'm missing...and...I'm thinking it's in the 'form_tag' code...dunno -- 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: rails 3 download - where ?
Fidel Viegas wrote: gem install rails --pre this will install rails 3.0 rc1 All the best, Fidel. thank you. this has helped upgrading, problem is I got the following error: ERROR: While executing gem ... (Errno::EINVAL) Invalid argument - .//cdesc-.yaml Any idee what this means ? Thnks, Dani -- 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: rails 3 download - where ?
If you want to upgrade from previous versions, I suggest you look into http://www.railsupgradehandbook.com/ I haven't really played with Rails 3 that serious. I am still using 2.3.8, and will only jump to rails 3 when it is production ready. But I have been playing with it from time to time and following quite a few books and tutorials. Regards, Fidel. On 8/3/10, Dani Dani li...@ruby-forum.com wrote: Fidel Viegas wrote: gem install rails --pre this will install rails 3.0 rc1 All the best, Fidel. thank you. this has helped upgrading, problem is I got the following error: ERROR: While executing gem ... (Errno::EINVAL) Invalid argument - .//cdesc-.yaml Any idee what this means ? Thnks, Dani -- 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.
Re: [Rails] Re: Strange error message when rendering the scaffold form
Stop your server and run it again -original message- Subject: [Rails] Re: Strange error message when rendering the scaffold form From: Jeff cohen.j...@gmail.com Date: 08/03/2010 14:10 On Aug 3, 2:14 pm, rodrigo3n rodrig...@gmail.com wrote: Hello everyone, I am developing my application and I created a scaffold called listas, but when I acess /listas/new I get this error message: NoMethodError in Listas#new Showing /home/rodrigo3n/code/listeiroo/app/views/listas/_form.html.erb where line #15 raised: undefined method `deep_symbolize_keys' for nil:NilClass Extracted source (around line #15): 12: % end % 13: 14: div class=field 15: %= f.label :nome %br / 16: %= f.text_field :nome % 17: /div 18: div class=field Trace of template inclusion: app/views/listas/new.html.erb I am using Rails 3RC and Ruby 1.9.2-rc2. This error is very strange to me because I did just create the scaffold via % rails g scaffold and then this error appeared. Do you know why? Did you migrate the database? Jeff purpleworkshops.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] parent controller_name (nested)
Hi people, i have this route in rails http://localhost:3002/gdm/9/cd/posts/10/comments we can see we have a namespace with prefix in gdm/9/cd/ also we have two controllers i will create a helper, and need get ther controllers name with commands i know i can get comments with %=controller_name% But how can i get posts Sorry for my bad english =/ Thx -- Rodrigo Mendonça (62) 8567-3142 -- 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.