[Rails] How to refernece polymorphic join association
I was wondering if you could help me with a quick question on writting polymorphic join associations. I have User has_many Favorite(polymorphic). The user has favorite Posts and Favorite Comments. I want set up a direct association on User to Post class User < ActiveRecord::Base has_many :favorite_posts , :as => :favoriteable, :source => :posts end I'm not quite sure how to describe that :favorite_posts association. Right now, I'm just using a little method to bridge the gap, but would prefer something more conventional, if possible. Any help would be appreciated! Thanks, -MgR -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] LIbrary to maintain manage browser sessions from command line
I have to update 80 pages' compliance terms on our clients existing CMS system. I can't do this on the back end, and it's a tedious task I'm looking to automate. These are all in an admin panel, so I am trying to find a library that could at least maintain a session and simulate browser interaction from the command line. Any leads would be helpful! Thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] JSON output replacing & with "\u0026 "
Hi, I'm outputting some database objects as static JSON files using a stand along ruby script.rb, that other could run outside of my rails app. When I use this script, the output replaces "&" with "\u0026." If I use the same code to output my JSON files in console, it outputs fine. I imagine there is some gem or something I'm not including in my script.rb that would resolve this. Thoughts? Thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: What are methods ending in =?
Got it - maybe. I found a good resource[1], but I am not sure I understand the value of the setter method in the first place. It would seem that benefit is being able to skip explicitly calling save on an object. Is that right? If I had this method defined on my class: def my_attribute=(some_value) @some_value = some_value end I could call: @object.my_attribute = new_value instead of: @object.my_attribute = new_value @object.save Is that the reason to define a setter method? [1] http://rubylearning.com/satishtalim/ruby_syntactic_sugar.html -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Associate HABTM Model on Create? Passing in a user_id?
Hi, Could anyone help me pass a user_id when creating a child record with a HABTM relationship? I'm basically trying to create a record from the following url /users/:id/tasks/new I tried several variants of the following, but keep getting various errors. My first attempt below yeilds 'invalid Users' error and the second yields a type mismatch error "user expected got string." <% form_for(@tasks) do |f| %> #things I tried: <%= hidden_field_tag "tasks[user_ids][]", params[:user_id] %> <%= f.hidden_field :user_ids, params[:user_id] %> <%= f.submit 'Create' %> <% end %> I get why I'm getting these errors, but haven't been able to figure out the correct syntax to get it to pass through. perhaps I've been making the wrong assumption that if I could pass the user_id to my create_action, rails would understand that it needed to create the HABTM between the new record and the user_id I'm referencing. Any help would be appreciated. Thanks! -MG -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Best Practicies: Combining Polymorphic Results?
Hi, I am trying to combine results on two related associations and was wondering if there were a best practicies way to do this. I basically have VendorCodes that are matched to both Vendors and VendorStaff. vendors have VendorCodes (polymorphic) vendorStaffs have VendoorCodes (polymorphic) I want to easily be able to derive something like: all_vendor_codes = vendor.vendor_codes + vendor.vendor_staffs.collect.vendor_code I have some models set up as, is there a better way to drive this other than the way I've done it? Thanks for any help! My Model: class Vendor < ActiveRecord::Base has_many :vendor_staffs has_many :vendor_codes, :as => :vendor_codable end class VendorStaff < ActiveRecord::Base belongs_to :vendors has_many :vendor_codes, :as => :vendor_codable end class VendorCode < ActiveRecord::Base belongs_to :vendor_codable, :polymorphic => true end -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Combining Polymorphic Results from Related Records?
Hello, I am trying to combine results on two related associations. I have some models set up as: class Vendor < ActiveRecord::Base has_many :vendor_staffs has_many :vendor_codes, :as => :vendor_codable end class VendorStaff < ActiveRecord::Base belongs_to :vendors has_many :vendor_codes, :as => :vendor_codable end class VendorCode < ActiveRecord::Base belongs_to :vendor_codable, :polymorphic => true end Is there a recommended way to derive this result: all_vendor_codes = vendor.vendor_codes + vendor.vendor_staffs.collect.vendor_codes -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Best practices to pass in Conditions to Rake task?
I'm trying to pass in conditions to a find command in a rake task. I'm still a little new to this, but what is the best practices for this? Should I be passing in a hash or..Any suggestions welcome! command line: rake mytask conditions='condition = 1' #mytask.rake def conditions ENV['conditions'] || ENV['conditions'] || nil end task :metadata => :environment do klass.find_each(:start => start, :conditions => conditions) do |record| #do stuff end end thanks! -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Restful routing question
Yep.. I have done both. This is the output from my rake routes. discard_contents_project POST /projects/:id/discard_contents(.:format) {:controller=>"projects", :action=>"discard_contents"} It seems like it should be a valid route... I found it: :method => :post. The method needed to be explicitly set since the route only allows the path if the request method is post. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Restful routing question
Oops. The rails link_to path is actually: discard_contents_project_path(current_project, :to_project_id => params[:id]) -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Restful routing question
Hi, I was wondering if you guys could help me out. i have a link_to url like so: discard_contents(current_project, :to_project_id => params[:id]) # => http://localhost:3000/projects/1163131/discard_contents?to_project_id=1121802 but I keep getting this "No action responded to 1163131" error I am guessing it's some issue with my routing configuration, but I'm not seeing it.. #from routes.rb map.resources :projects, :member => { ... :move_or_discard_contents => :any, :move_contents => :post, :discard_contents => :post }, :collection => { ... } do |project| end /projects/discard_contents/1163131?to_project_id=1121802 works. any ideas? -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Combine if and do in a single line?
Is there a way to combine if and do into a single line? items.each do |item| if current_user.admin? #do stuff end Thanks! -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Action to Render Image for Download
I got it, with the help of a friend. send_file art.list_image.path(:original), :type => art.list_image_content_type, :disposition => 'attachment', :filename => art.id -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Action to Render Image for Download
Hi, I'm trying to set up an action that will send an image to the browser as an attachment for download using paperclip. Sadly, I keep getting stuck. Insead, I keep sending an empty image to the browser. Anyone have any luck or any ideas? def download_image art = Art.find(params[:id]) send_file art.list_image.url(:original), :type => art.list_image_content_type, :disposition => 'attachment' end Thanks so much. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Using module methods in Rake task& model?
Hu? Did you not read my last post? You wrote almost exactly the same questing twice. You have to both require the file, then include the module. ###rake_file.rb require 'lib/modules/your_module_filename.rb' namespace :your_rake_task do include your_module_name #do stuff end -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Using module methods in Rake task& model?
Yep. I had to both require the file then include the module: require 'lib/modules/report_csv_process.rb' include ReportCsvProcess -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Trunicating Names in options_from_collection_for_select
Anyone know how I could trunicate the names of a passed in array in options_from_collection_for_select? I tried a few things but nothing worked. Any ideas would be appreciated! <%= options_from_collection_for_select available_projects, :id, :name, @selected_project_id %> -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: Using module methods in Rake task& model?
I was a little off, but still haven't quite figured it out. I currently have: > /lib/module/order_process.rb > module order_process > def process_order(id) > #do stuff > end > > > /lib/tasks/ordering.rake > > include 'order_process.rb' > namespace :send_report do > task :order => :environment do > process_order(id) > end > end > > /app/models/segment.rb > class Segment < ActiveRecord::Base > include 'report_csv_process.rb' > >bla bla > > end I tried removing the single quotes, without luck -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Using module methods in Rake task& model?
Hello, I'm trying to use some methods I'm defining in a module in a model and my rake task. How can I do this? Any help would be appreciated. I've currently got the following, but my rake task can't access the methods in my module. Instead, I get.. undefined local variable or method `report_csv_process' for # /lib/module/order_process module order_process def process_order(id) #do stuff end /lib/tasks/ordering.rake include order_process namespace :send_report do task :order => :environment do process_order(id) end end /app/models/segment.rb class Segment < ActiveRecord::Base include report_csv_process bla bla end -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---