[Rails] Associated object is not set correctly after creating with belongs_to and has_one associations

2010-10-06 Thread szimek
Hey, I've got 2 models: User and Account::Website that look like this: class User < ActiveRecord::Base has_one :website_account, :class_name => "Account::Website", :dependent => :destroy end class Account::Website < ActiveRecord::Base belongs_to :user, :touch => true before_validation :as

[Rails] Re: Problem with callbacks and has_many :through association

2010-06-22 Thread szimek
Thanks for the reply! Basically the problem was that we were using a form were we had dynamically added/removed hidden fields with venue IDs - they were later passed as an array (:params => {:venue_ids => [something]}), that's why I was mainly interested in reply#venue_ids= assignment. I solved it

[Rails] Problem with callbacks and has_many :through association

2010-06-21 Thread szimek
Hey, I've got a following scenario: Reply has_many :venues, :through => :venue_suggestions. When user answers to a question he can add venues to it as suggestions. The problem is that these venues (actually their IDs) are added to the reply form, before the reply is created. Wnever a venue is adde

[Rails] How to override generated named route helpers?

2010-05-21 Thread szimek
Hey, where exactly are these methods defined? I'd like to use alias_method to set some parameters before calling the original methods. Cheers, Szymon -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to r

[Rails] How to automatically set params based on passed object when generating a route?

2010-04-22 Thread szimek
Hi, having i.e. a post model that has many categories - is it possible for member routes like i.e. post_path(post) to generate path like "/ posts/:post_category_name/:post_id" without manually passing the category param? Does anyone know if there's a gem or if I can simply override the post_url me

[Rails] Nested attributes with required protected attributes

2010-03-26 Thread szimek
Hi, I've got 3 models: Comment, Venue and User. Comment has many :venues and belongs to :user. Venue belongs to :user as well. When adding a comment, user should be able to attach a venue to it. In Venue model "user_id" attribute is protected and it is required as well - this causes problem when

[Rails] Strange error on the first request - trying to setup Rails 2.3.5 with Bundler

2010-03-05 Thread szimek
I'm trying to use Bundler for existing Rails 2.3.5 app and got a very strange problem. The problem is that on the very first request only the contents of the action view file are rendered - i.e. when loading the home page (controller: home, action: index) I get only contents of the app/views/ home

[Rails] Rails 3: How to properly fetch layout name?

2010-02-21 Thread szimek
Hi, I'm trying to update shoulda gem to be Rails 3 compatible and got a problem with fetching layout name. There's the following code in shoulda: @controller.response.layout which in Rails 2 returns i.e. 'layouts/application'. When this code is executed in Rails 3, Rails prints out deprecati

[Rails] Rails 3: Can Bundle.require be called after Application class is defined?

2010-02-15 Thread szimek
Hi, I'm trying to use shoulda in Rails 3 and there's a small problem. I'm using branch "rails3" from shoulda repository - http://github.com/thoughtbot/shoulda/tree/rails3. The problem is that shoulda tries to auto load some files from predefined paths and uses Rails.root to build these paths, how

[Rails] Re: How to create Rails 3 migration generator?

2010-01-30 Thread szimek
It should be Rails::Generators::Migration.next_migration_number, not ActiveModel::Generarators::Base.next_migration_number :) On Jan 30, 3:30 pm, szimek wrote: > So the solution for now is to make the "next_migration_number" method > inside my generator to call a class met

[Rails] Re: How to create Rails 3 migration generator?

2010-01-30 Thread szimek
ss method, so you just need to do: > >   ActiveRecord::Generators::Base.next_migration_number > > Feel free to work in a patch and assign to me when it's done. If not > in mood for a patch, please create a ticket on Lighthouse and assign > to me, so I can tackle it later. >

[Rails] Re: How to create Rails 3 migration generator?

2010-01-30 Thread szimek
ssible with migrations. > > Also see:http://guides.rails.info/generators.htmlfor more details ;) > > Good luck! > > Kristian > > On Jan 29, 9:54 pm, szimek wrote: > > > > > Hi, > > > I'd like to add Rails 3 compatible generator to acts_as_taggable_on

[Rails] How to create Rails 3 migration generator?

2010-01-29 Thread szimek
Hi, I'd like to add Rails 3 compatible generator to acts_as_taggable_on gem (all it does is call "migration_template" method) and got a problem with "next_migration_number" method not being implemented. For ActiveRecord this method is defined in ActiveRecord::Generators::Base class, which inherit

[Rails] Should fields_for for has_many association execute block even if the collection is empty?

2009-09-24 Thread szimek
Hi, I had a problem where fields_for block was executed once, even if the association collection was empty - child_form.object was nil of course. Adding accepts_nested_attributes to parent model solved the problem - block is now executed correctly for each instance of the collection. Is this pro

[Rails] Re: Does anyone know where can I get US zip codes with time zones?

2009-07-25 Thread szimek
Is it possible that 2 regions in US at any time of year have the same time offset, both are in daylight savings time, but actually have different time zones? If not, then it should be easy to map this data to Rails time zones. On 24 Lip, 20:21, Philip Hallstrom wrote: > > we ask user for his zip

[Rails] Does anyone know where can I get US zip codes with time zones?

2009-07-24 Thread szimek
Hi, we ask user for his zip code and currently we also ask for this time zone (only US). It's a bit redundant, so I'd like to figure out user's time zone based on his zip code. The problem is that all services I've seen that provide such data, provide only time offset and daylight savings flag f

[Rails] Is it possible to omit HTML id attribute when using form helpers?

2009-07-24 Thread szimek
Hi, I'm displaying i.e. 100 forms that differ only in action and right now form inputs in every form have the same ids. I could overwrite them somehow to make them unique, but I don't really need them at all. I tried setting :id to nil or false, but it displays generated id in this case. Thanks

[Rails] How to reuse named scope conditions with eager loading

2009-03-12 Thread szimek
Hi, I've got Channel model that has many events. Event belongs to channel and additionally has a named scope called "current". I need to iterate over each channel and then over each "current" event for given channel i.e.: @channels.each do |channel| channel.events.current do |event| ...

[Rails] Re: what's happened to acts_as_state_machine

2009-02-25 Thread szimek
The way it is now written there shouldn't be any difference between using aasm with AR and any other Ruby class. Here's very basic example from our User model: class User < ActiveRecord::Base include AASM aasm_column :state # I guess it's the only AR specific method here aasm_initial_st

[Rails] Re: find_or_create_by_...

2009-02-25 Thread szimek
Hi, I'm not exactly sure what you're asking about, but if you want to find out if the result was already in the db or was it just created, you could use find_or_initialize_by instead: post = Post.find_or_initialize_by_title("something completely different") post.new_record? # false if it was fou

[Rails] Rails 2.3.0 - ActionController::AbstractRequest not being loaded

2009-02-10 Thread szimek
Hi, I got a plugin that extends ActionController::AbstractRequest. After updating Rails from 2.2.2 to 2.3.0 I'm getting the following error: 'load_missing_constant': uninitialized constant ActionController::AbstractRequest (NameError) I've already seen people having similar problems with i.e. T

[Rails] How to set up Ajax.Request, so that format.json block is executed?

2009-01-19 Thread szimek
Hi, I've got format.js block in my code that returns some RJS. I'm trying to do edit-in-place using RESTful approach and I've added format.json block to the update action, but I can't figure out how to setup Ajax.Request, so this format.json block is actually executed. I've tried adding content

[Rails] Re: REST: transfer data between applications

2009-01-16 Thread szimek
Your login system should provide a way to authenticate using HTTP basic authentication - most authentication plugins do so i.e. restful_authentication. If you're not using any plugin, check http://railscasts.com/episodes/82 to see how to set it up. Instead of using plain Net::HTTP, you can use Ac

[Rails] Problem with render :layout with yield :something inside in Rails 2.2.2

2009-01-16 Thread szimek
Hi, I got something like this: _inner_layout.erb.html <%= yield %> <%= yield :sidebar %> index.erb.html <% render :layout => "inner_layout" do %> should be rendered only once <% end %> After switching from Rails 2.1 to 2.2 the code above renders "should be rendered only once" twice. If I add

[Rails] Re: ActiveResource - xml and json format return different results

2008-12-02 Thread szimek
On 2 Gru, 15:56, Frederick Cheung <[EMAIL PROTECTED]> wrote: > On 2 Dec 2008, at 14:52, szimek wrote: > > > > > > > > > Hi, > > > I'm using Rails 2.1.2. and I wanted to switch ActiveResource format to > > JSON and thought that it will

[Rails] ActiveResource - xml and json format return different results

2008-12-02 Thread szimek
Hi, I'm using Rails 2.1.2. and I wanted to switch ActiveResource format to JSON and thought that it will work smoothly, but unfortunately it wasn't the case. XML and JSON formats generate different objects: XML version #Mon Nov 28 11...}> JSON version ##Mon Nov 28 11...}> As you can see, when

[Rails] Constants in models are initialized before fixtures are loaded?

2008-11-05 Thread szimek
Hi, here's simplified code from the model: class Foo < AR::Base FIRST = Foo.first.id end The problem is that when testing I get well known error: "Called id for nil...". I guess that this constant is initialized before the fixtures are loaded. Is there any way to fix it? --~--~-~--~-

[Rails] Re: How to easily cache single AR object?

2008-10-23 Thread szimek
ingleton > >   def self.by_name(name) >     self.instance.by_name(name) >   end > >   def by_name(name) >     return @active_style if @active_style && @active_style.name == > name > >     @active_style = Style.find_by_name(name) >     return @active_style >   end &g

[Rails] How to pass parameters to after_update callback?

2008-10-23 Thread szimek
Hi, I got i.e. Ticket and TicketChange models and would like to create TicketChange object whenever Ticket object is updated. Currently I'm creating new TicketChange in Ticket#after_update callback and simply serialize slightly modified ticket.changes hash. Ticket can be updated using 2 ways - u

[Rails] How to easily cache single AR object?

2008-10-22 Thread szimek
Hi, I got a mailer that uses dynamic stylesheets, so when creating an email I'm doing Style.find_by_name("newsletter"). The problem is that it's fetching the same Style record for each email it creates and when sending newsletters there can be a lot of them. I could simply fetch this record in c

[Rails] Sending thousands of email with ar_mailer

2008-10-22 Thread szimek
Hi, to send an email with ar_mailer I need to generate it and save it to the db, right? Currently the code looks very simple: Newsletter.recepients.each do |recepient| NewsletterMailer.deliver_dedicated(request, recepient, newsletter) end But for i.e. 3 receivers it's going to take a long

[Rails] Re: Problem finding method while testing a helper

2008-09-07 Thread szimek
On 7 Wrz, 16:05, "H. Wade Minter" <[EMAIL PROTECTED]> wrote: > I'm trying to test the code in my helpers, using the great Viget Labs   > helper_me_test plugin.  However, I'm running into an oddity (unrelated   > to the plugin - it was happening when I was trying to roll my own   > solution as well

[Rails] How to properly upload a file in the same form as a parent model?

2008-09-07 Thread szimek
Hi, let's say you got a Gallery model that has one (to simplify things a bit for now) Image (attachment_fu model). Gallery has i.e. title and description, both fields are required. In the "create new gallery form" you can set title, description and upload the image as well. What to do if the gal