hi thanks a lot for your help so far.

I got most of my problems fixed tonight but just have one tiny issue
left.  When I go to the create form to write a new post, the users
drop-down menu is populated with data of the following form: "#<User:
0x9d58ce4>".  I'd like the username of the user to appear here instead
of "#<User:0x9d58ce4>"

The exact same thing was happening in the list and show views whenever
the user was referenced, but I fixed that by overriding the
user_column method in my model:

    def user_column(record)
      if record.user.nil?
        active_scaffold_config.list.empty_field_text
      else
        record.user.username
      end
    end

I tried to do something similar (see code below) to override the
user_form_column method but rails complains about there being no
username method

    def user_form_column(record, input_name)
       select(:record, "record.user.username", :name=> input_name )
    end

So I think I'm close but can't quite get my head round what I need to
do to make usernames appear in the create/edit form for the posts
resource.

Does anyone know how to fix this?  Thanks in advance,


On Jun 17, 9:37 am, "Sergio Cambra .:: entreCables S.L. ::."
<[email protected]> wrote:
> On Jueves, 17 de Junio de 2010 10:05:22 stephenmurdochescribió:
>
>
>
> > I have a Post model and my controller looks like this:
>
> > class Admin::PostsController < Admin::AdminController
> >   active_scaffold :posts do |config|
> >     config.columns = [:title, :body, :user_id]
> >     config.list.columns = [:title, :body, :user_id]
> >   end
> > end
>
> > Each Post belongs to one User, each User has many Posts.  Pretty
> > basic.
>
> > First Question:  Using the code above, when I go to create or edit a
> > post, the user_id appears as an input field in the form and the poster
> > actually has to manually enter their user_id in order for the
> > association to be written to the database.  How can I do this
> > automatically.  I know how to remove the user_id field and label from
> > the form.  Do I have to do this in my model?  Like a before_create
> > filter or something?
>
> You can use before_create in the model, becuase ActiveScaffold enables you to
> use current_user in models, or you can define before_create_save in the
> controller:
> def before_create_save(record)
>   record.user = current_user
> end
>
>
>
> > Second Question:  I want to allow admins to be able to change the
> > user_id for each post.  This would best be accomplished by having a
> > drop-down select menu that is greyed out unless the user is an admin.
> > Again, I think I can figure out how to grey the select-box out for
> > admins, but I am having trouble getting the user_id to appear in a
> > select box in the first place.  From reading the docs, I was under the
> > impression that the following code might work, but it just throws up a
> > noMethodError (which I would be happy to post, if anyone needs to see
> > it):
>
> >     config.columns[:user_id].form_ui = :select
> > I also tried this code using "record_select" instea of just "select"
>
> select form_ui must be used with association columns (:user) instead of
> foreign keys (:user_id). Usually ActiveScaffold uses associations instead of
> foreign keys.
>
> --
> 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