Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert How to show a list of radio_bu...

Replytotopic

How to show a list of radio_button Categories in another model

Posted in Forums : Ask a Rails expert

 
Highres_10652850

Authority 25
Posting Rating 0
Sign in to rate this post

Hi,
Am new to Rails and Ruby. I have 2 models Job and Category. I want to select a category from a radio_button list when creating a new job in the jobs => :new action.

Could someone tell me how to deal with the form_for @jobs given that this same form is also used to upload a logo image.

 
81539342a46008603039d00c8a7ab03d

Authority 62
Posting Rating 99
Sign in to rate this post

You’ll just have something like this, within your form_for block:

<% Category.all.each do |category| %>
  <label><= f.radio_button :category_id, category.id %> <=h category.name.titleize %></label>
<% end -%>

That’ll work in your edit form as well.

 
Highres_10652850

Authority 25
Posting Rating 0
Sign in to rate this post

Thanks a lot Jason. It worked but do i have to do this bq.<% form_for [@job, @category], :html => {:multipart => true } do |f| %> bq. ?

I have been ill for a while but am back now.

Now am wondering how to populate the table :category_id so that when I do @jobs.category.find(params[:category_id]) if this is right,

i return all the jobs under that category. How do I deal with the actions in the controller/model?

Thnks

 
Highres_10652850

Authority 25
Posting Rating 0
Sign in to rate this post

OK Jason. Looks like its not working.

I wanted to be able to select a category from the list of radio buttons and associate the category with the job. I get an error saying “Could not find Category without an id”

What am I doing wrong?

 
664297762

Authority 50
Posting Rating 95
Sign in to rate this post

Hi Nelson,

for your trouble Jason has already been provided good solution..

may be there is problem at other place

I’m providing you sample code.. which is working perfect at my side.

http://pastie.org/1192782

Just go through above link.. I hope this will help you..

Good Luck ;)

-Ganesh K

Replytotopic

Other Recent Topics

Ask a Rails expert : nested application ApplicationController get called intead of children::ApplicationController

Ask a Rails expert : Best way to structure a database for a large/static dataset

Ask a Rails expert : Ruby Developer (ROR) - Scottish based (Remote working from within the UK)

Ask a Rails expert : Above Ground Pool Supplies

Ask a Rails expert : How to get url params in observer or model in Rails 3.1

Ask a Rails expert : What can persuade you to hire Junior Ruby devs with significant PHP experience?

Ask a Rails expert : What industry value does the Ruby or Rails Certification currently have?

Ask a Rails expert : Louis Vuitton Damier Azur Canvas specially sale ( www.salecheaplouisvuitton.com )

Ask a Rails expert : ·How to check errors/puts statements from ruby files which are under cronob

Ask a Rails expert : Louis Vuitton cheap Soft Sided Luggagespecial offer( www.salecheaplouisvuitton.com )

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel