ruby on rails 3.2 - Couldn't find Category without an ID Error message -


i'm new ruby on rails, , i'm experiencing problems

i'm trying affect cathogory id object.

so controller action:

  def create_card     @card = card.new(params[:card])      if !params[:category].blank?      @card.category_id = params[:category_id]     end     @category = category.find(params[:id])     @card.category_id = @category.id     @card.save      if @card.save       flash[:notice] = "card created"       redirect_to :action => "card_information", :id => @card.id     else       render new_card_path     end    end 

and view piece of code:

= form_for @card, :url => create_card_path |f|   .row     .span3       = f.label "card name"       = f.text_field :title    .row         .span3       = f.label "card category"       = select_tag :category_id, options_for_select(category.all.collect{ |c| [c.title, c.id]})     %br/  .row    .span3      = f.submit "submit", :class => "btn btn-primary" 

the category_id being passed controller params[:card][:category_id], , therefore being assigned @card when card.new(params[:card]). can remove code action you're searching category, etc:

def create_card   @card = card.new(params[:card])    if @card.save     flash[:notice] = "card created"     redirect_to :action => "card_information", :id => @card.id   else     render new_card_path   end  end 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -