i have a registration form ,i want to store data in corresponding user
table in that hobbies field
,i want to store all hobbies in one column so i take multiple check
boxes and store in one array
all checked values for that i am using below tag,but not working,please
any suggestion
<%= check_box(:user ,:hobbies,:value =>‘Games’) %>Games
<%= check_box :user , :hobbies,:value =>‘Music’ %>Music
<%= check_box :user , :hobbies,:value => ‘Shopping’%>Shopping
the above user is table name ,hobbies is column name
On Dec 28, 2:57am, “Durga B.” [email protected] wrote:
You need to use check_box_tag, and the name of the parameter needs to
end in []. THis will result in params[:foo] being an array which you
an then do something sensible with.
Fred
thank you ,thank you fred ,it will help in mytask
Prasad B. wrote in post #970999:
i have a registration form ,i want to store data in corresponding user
table in that hobbies field
,i want to store all hobbies in one column
No you don’t. That’s VERY BAD database design. Please read about DB
normalization.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Sent from my iPhone
please it is urgent for me any suggestion urgent
Frederick C. wrote in post #971033:
On Dec 28, 2:57am, “Durga B.” [email protected] wrote:
You need to use check_box_tag, and the name of the parameter needs to
end in []. THis will result in params[:foo] being an array which you
an then do something sensible with.Fred
Thank you so much fred for your suggestion ,it will create for user
registration page,please give me a solution for in user profile editing
how it works .example i have 3 check boxes in editing ,which one is
select in previous they are automatically checked please give any
solution
Thanks & Regards
prasad
On 30 December 2010 13:39, Prasad B. [email protected] wrote:
please it is urgent for me any suggestion urgent
Since you have not quoted any previous message it is not clear what
you are wanting help with.
Looking back at your original post it is not clear exactly what you
are having difficulty with. I assume you have followed Marnen’s
advice in his email. So having done that can you explain what the
problem is?
Colin
i have a registration form ,i want to store data in corresponding user
table in that hobbies field
,i want to store all hobbies in one column so i take multiple check
boxes and store in one array
all checked values for that i am using below tag,but not working,please
any suggestion
<%= check_box(:user ,:hobbies,:value =>‘Games’) %>Games
<%= check_box :user , :hobbies,:value =>‘Music’ %>Music
<%= check_box :user , :hobbies,:value => ‘Shopping’%>Shopping
the above user is table name ,hobbies is column name
the above check boxes ,i want in registration,validating and mainly
editing i want how to possible
On 30 December 2010 13:51, Prasad B. [email protected] wrote:
I am assuming that this is in response to my post, but again you have
not quoted the previous message so I do not know. When replying
please insert your reply into the previous message so that it is
easier to follow the thread. Thanks
i have a registration form ,i want to store data in corresponding user
table in that hobbies field
,i want to store all hobbies in one column so i take multiple check
boxes and store in one array
all checked values for that i am using below tag,but not working,please
any suggestion
<%= check_box(:user ,:hobbies,:value =>‘Games’) %>Games
<%= check_box :user , :hobbies,:value =>‘Music’ %>Music
<%= check_box :user , :hobbies,:value => ‘Shopping’%>Shopping
the above user is table name ,hobbies is column name
It has already been suggested that it is not a good idea to store the
hobbies all in one column. What did you learn from reading about
database normalisation?
Hint: You could have a hobbies table and then have a
has_and_belongs_to_many association between the models. Have a look
at the Rails Guide on ActiveRecord Associations if this is not
familiar to you.
Colin
Hi thank you very much ,you got my point and understand my thinking you
suggest good idea ,i am new to ruby on rails so please suggest rails
tags also for array of check boxes.How serialize array of that hobbies
object and store in database
On 30 December 2010 13:51, Prasad B. [email protected] wrote:
i have a registration form ,i want to store data in corresponding user
table in that hobbies field
,i want to store all hobbies in one column so i take multiple check
boxes and store in one array
At the risk of making the the thread start sounding like a broken
record : “no you do not”.
It’s a dreadful idea to try to store all the hobbies in one (comma
separated, I assume) field.
Set up an association properly, and have done with it.
all checked values for that i am using below tag,but not working,please
any suggestionthe above check boxes ,i want in registration,validating and mainly
editing i want how to possible
If you insist on implementing your horribly broken solution to the
problem, then you’ll need some helper methods in your model that take
your single column and break it into an array, and take an array of
ids (from the params array in the controller) and join it back into
your field, such as:
def hobby_ids
self.hobbies.split(“,”)
end
def hobby_ids=(supplied_ids)
self.hobbies = supplied_ids.join(“,”)
end
No-one is going to “help” more than this, as the correct solution is
to “make an association”, anything else is a hideous bodge that is
going to lead to heartache and worry.
What is Mass Assignment?
Can you give me a clear idea about that with an example?
On 31 December 2010 02:52, Prasad B. [email protected] wrote:
Hi thank you very much ,you got my point and understand my thinking you
suggest good idea ,i am new to ruby on rails so please suggest rails
tags also for array of check boxes.How serialize array of that hobbies
object and store in database
In order to understand better the basics of RoR I suggest you work
through some tutorials and guides. Start with working through all the
Rails Guides and also railstutorial.org (which is a free tutorial when
used online). Then you will be able to answer most of your own
questions. Come back and ask again if you still have problems.
Colin
On 31 December 2010 02:52, Prasad B. [email protected] wrote:
Hi thank you very much ,you got my point and understand my thinking you
suggest good idea
I’ve no idea who you’re thanking, as you didn’t quote any previous
message.
,i am new to ruby on rails so please suggest rails
tags also for array of check boxes.
googling for “ruby rails tutorial” will give you lots of results. I
recall that you’ve already been pointed at the documentation for
associations, and it might be good for you to get a book to work
through - “Agile Web D. With Rails” is highly recommended.
How serialize array of that hobbies
object and store in database
You can use the “serialize” method on a model… but that’s not
what you want to solve your problem - you want to use associations…
it may have been mentioned already.
Sorry for sounding terse… got a plane to catch
you can use attr_accessible.