On Miércoles, 22 de Septiembre de 2010 15:07:28 otty escribió:
> Hi,
>
> chaining wont work in my little app. i tryed it with a basic
> bookstore, just a user wich choose one book when created, some books
> and authors. if i create a new user, the books are not filtered when
> choosing an author ,they are just set back to zero ( first entry).
> whats wrong with that ?
>
> I'm using Rails 2.3.8 and latest AS from git master
>
> #my user helper
>
> module UsersHelper
> def options_for_association_conditions(association)
> if association.name == :book
> {'books.author_id' => @record.author_id}
> else
> super
> end
> end
> end
Maybe you have to use @record.author.id, probably ActiveRecord don't set
author_id when you set author association until save the record, which is not
done on render_field. What is the sql issued when book field is refreshed?
>
> #books controller:
>
> class BooksController < ApplicationController
>
> active_scaffold :books do |config|
> config.label = "Books"
> config.columns = [:title, :author]
> list.columns = [:title, :author]
> list.sorting = {:title => 'ASC'}
>
> columns[:author].form_ui = :select
> authors = Author.find(:all, :order => "`name` ASC")
> columns[:author].options = { :options => authors.collect{|a|
> [a.name, a.id]}}
If author is an association, that line does nothing. In other case it's wrong,
it won't work in production mode, because you are fixing options to authors
available at application startup. In development mode it works because classes
are loaded for each request. You should use a per-request configuration with a
before filter, or better, a form override (helper method).
> end
> end
>
>
> #my users controller:
>
> class UsersController < ApplicationController
> active_scaffold do |config|
>
> config.columns[:author].form_ui = :select
> authors = Author.find(:all, :order => "`name` ASC")
> columns[:author].options = { :options => authors.collect{|a|
> [a.name, a.id]}}
>
> config.columns[:author].update_column = :book
>
> config.columns[:book].form_ui = :select
> books = Book.find(:all, :order => "`title` ASC")
> columns[:book].options = { :options => books.collect{|b| [b.title,
> b.id]}}
>
> end
> end
Same comment as above, book and author options are wrong.
>
> if i comment the collection ( like in the API documentation ) , i got
> "nil object" errors.
What errors do you get? Send a full backtrace, removing backtrace silencers
>
> whats wrong? do i need something else ?
>
> regards,
--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en.