On Jueves, 20 de Agosto de 2009 03:48:04 Paul Hamann escribió:
> Thanks again for all your help. Sadly, I'm still missing something. [BTW,
> there's a search_sql in the thread example, but not in the wiki example?]
>
> Here's the code:
>
> ============ schema ===============================
>
>  create_table "survey_questions", :force => true do |t|
>     t.integer  "survey_id",     :limit => 11
>     t.text     "question_text"
>     t.datetime "created_at"
>     t.datetime "updated_at"
>   end
>
>   create_table "surveys", :force => true do |t|
>     t.string   "name"
>     t.datetime "created_at"
>     t.datetime "updated_at"
>   end
>
> ============ Model: survey.rb =========
>
> class Survey < ActiveRecord::Base
>
>   has_many :survey_questions
>
>   def to_tabel
>    "#{name}"
>   end
> end
>
> ============Model: survey_question.rb ====
>
> class SurveyQuestion < ActiveRecord::Base
>
>   belongs_to :survey
>
>   def to_label
>    "#{question_text}"
>   end
> end
>
> ================= survey_helper.rb ==================
>
> module SurveyHelper
>
>    def options_for_association_conditions(association)
>      if association.name == :survey_question
>       {'survey_questions.survey_id' => @record.survey_id}
>      else
>       super
>      end
>    end
>
> end
>
> ============= survey_controller.rb =====================
>
> class SurveyController < ApplicationController
>
>  layout "default"
>  active_scaffold :survey
>
>  active_scaffold do |config|
>     config.columns[:name].form_ui = :select
>     config.columns[:name].options = { :update_column => ':survey_question'
> } config.columns['question_text'].form_ui = :select
>   end
> end

form_ui select automatically fills the options when column is an association 
(neither name nor question_text are associations). You can't set question_text 
form_ui from SurveyController because that column belongs to SurveyQuestion 
model, you should do it in SurveyQuestionsController.

I don't understand what you want to get. What options should be shown for 
name?

>
> ==========================================================
>
> --- On Wed, 8/19/09, Kerry Foley <[email protected]> wrote:
> > From: Kerry Foley <[email protected]>
> > Subject: Re: Yet another question on dynamic selects
> > To: [email protected]
> > Date: Wednesday, August 19, 2009, 5:32 PM
> >
> > It sounds like your column name is incorrect. You didn't
> > paste you're
> > code so I can't say for sure. You should be doing something
> > like
> > config.columns[:project_type].form_ui = :select 
> > #belongs_to
> > or
> > config.columns[:regions].form_ui =
> >
> > :select   #has_many
> >
> > it shouldn't be "_id" - it's the association name, not the
> > column name.
> >
> > There are examples on the wiki e.g Getting Started;
> > http://wiki.github.com/activescaffold/active_scaffold
> >
> > You don't need to build the select.
> >
> > I think there's a more or less complete set of controller,
> > model and
> > helper code for what you are trying to do in the thread
> > previously sent.
> >
> > http://groups.google.com/group/activescaffold/browse_thread/thread/2ae130
> >edb1d0e2d2
> >
> >
> > Regards,
> > Kerry
> >
> > Me wrote:
> > > Bare with me here.  I'm a little slow. So I tried
> >
> > the code, and I get:
> > > You have a nil object when you didn't expect it!
> > > The error occurred while evaluating nil.form_ui=
> > >
> > > Is there enough smarts built-in to populate the select
> >
> > boxes? Or do I
> >
> > > need something like:
> > >
> > > a= Author.find(:all).collect { |a| a.name  }
> > >
> > > If that kind of code is required, do I put that in the
> >
> > helper form
> >
> > > override?  Any chance I can see one complete
> >
> > example that works?  I've
> >
> > > been banging my head on this for a while.  When I
> >
> > Google, I just come
> >
> > > across more people that have been banging there heads
> >
> > on this.
> >
> > > Thanks! Paul
> > >
> > > On Aug 19, 1:58 pm, Kerry Foley <[email protected]>
> >
> > wrote:
> > >   
> > >
> > >> http://groups.google.com/group/activescaffold/browse_thread/thread/2a.
> > >>..
> > >>
> > >> Regards,
> > >> Kerry
> > >>
> > >> Me wrote:
> > >>     
> > >>
> > >>> Greetings!  First post.
> > >>>       
> > >>> I've been greping the web for an AS example of
> >
> > populating a parent
> >
> > >>> select box, and then dynamically changing a
> >
> > child select box through
> >
> > >>> an "onchange" event.  I've seen the
> >
> > observer approach, but not with
> >
> > >>> AS.  Is there support for such a thing?
> > >>>       
> > >>> I found this thread where this same question
> >
> > was asked.
> >
> > >>>       
> > >>> http://www.mail-archive.com/[email protected]/msg00108.
> > >>>... 
> > >>> The poor guy got a rather prickly
> >
> > response.  He eventually posted his
> >
> > >>> solution in the last msg of the thread. 
> >
> > Unfortunately, I can't get
> >
> > >>> that solution to work.  The example [in
> >
> > plain English] was, "Surveys
> >
> > >>> have many survey_questions and surveys
> >
> > have_many survey_options."  If
> >
> > >>> options are meant to be answers to questions,
> >
> > then it should be
> >
> > >>> "Surveys have many questions.  Questions
> >
> > have many options [multiple
> >
> > >>> choice]."   That would be three
> >
> > levels.  I tried looking at the
> >
> > >>> survey_options table as some type of join with
> >
> > both foreign keys
> >
> > >>> [survey_id, survey_question_id].  If that
> >
> > were the case, then survey
> >
> > >>> "has many questions through
> >
> > survey_options."  That wasn't listed in
> >
> > >>> the example.  Clearly, I'm confused
> >
> > somewhere.
> >
> > >>>       
> > >>> I would appreciate it if someone could explain
> >
> > the example referenced
> >
> > >>> in the last message of the thread linked to
> >
> > above.  Alternatively. I
> >
> > >>> would appreciate a clear example of this
> >
> > pattern.  I think that this
> >
> > >>> is a common situation where some documentation
> >
> > would benefit many
> >
> > >>> people.
> > >>>       
> > >>> Thanks! Paul
> > >>>       
> > >
> > >   
>
> 
-- 
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to