Hi, I''m just starting with Rails and i''m trying to do something like this: <%= start_form_tag :action => ''add_user'', :id => @social_event_group %> <%= select ''user'', ''id'' , User.find_all.collect {|u| [ u.login, u.id ] }%></p> <%= submit_tag "Add User" %> <%= end_form_tag %> and i''m doing this in the "add_user" action : user = @params[:user] @social_event_group.users<<User.find(user[:id]) I guess i cannot simply pass the object and have to get it from the DB in my controller right?! But isn''t there a way to simply pass @params[:user_id]?! Instead of (@params[:user])[:id] ?! By the way, how can i create a list with multiple selection and how can i see the logs for ActionMailer? Regards, Nelson
Isn''t there any helper for table associations?! One could define an attribute selecting the column to be used for listing purposes and code could be generated. inEvo wrote:> Hi, > > I''m just starting with Rails and i''m trying to do something like this: > > <%= start_form_tag :action => ''add_user'', :id => @social_event_group %> > <%= select ''user'', ''id'' , User.find_all.collect {|u| [ u.login, u.id ] > }%></p> > <%= submit_tag "Add User" %> > <%= end_form_tag %> > > and i''m doing this in the "add_user" action : > > user = @params[:user] > @social_event_group.users<<User.find(user[:id]) > > I guess i cannot simply pass the object and have to get it from the DB > in my controller right?! > > But isn''t there a way to simply pass @params[:user_id]?! Instead of > (@params[:user])[:id] ?! > > > By the way, how can i create a list with multiple selection and how > can i see the logs for ActionMailer? > > Regards, > > Nelson > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Julian ''Julik'' Tarkhanov
2005-May-17 15:09 UTC
Re: Noob - ActionView::Helpers::FormOptionsHelper::select
On 17-mei-2005, at 13:43, inEvo wrote:> Isn''t there any helper for table associations?! > > One could define an attribute selecting the column to be used for > listing purposes and code could be generated. >I recently wrote a couple of helpers for this - checkbox_array and multiselect (that allow me to comfortably build habtm relationship edtitors - Rails handles simple selects on it''sown pretty nicely). They work the same as Rails built-in helpers: checkbox_array (model_name, model_field, members_array, id_field, name_field, existing_collection = [], options=[]) multiselect (model_name, model_field, members_array, id_field, name_field, existing_collection = [], options = []) They work the same way but I find checkobx arrays more intuitive for users (they usually don''t realise how a multiselect works) However, I had to add an ActiveRecord#related_collection= method for all of the relationships that I have, which collects the related objects by ID and shifts them one by one into the collection. Which was kinda dissapointing, because I don''t get why we can shift into the collection but cannot do a simple batch assignment? The methods I had to define are really boilerplate and about 10 lines long - I expected Rails can handle that for me but no avail.>-- Julian "Julik" Tarkhanov