Ruby on Rails
Thursday, November 26, 2015
I'm able to follow the docs and create categorie from the rails console but I'm having trouble working those instructions into my controller I know this is wrong I dunno if I can use category instead of @category for the object The browser returns syntax error for the respond to do |format| line unexpected identifier
# POST /categories
# POST /categories.json
def create
category = Category.new(category_params)
parent=Category.find(#{params[:parent_id]})
category.move_to_child_of(parent)
respond_to do |format|
if cat.save
format.html { redirect_to admin_categories_path, notice: 'Category was successfully created.' }
format.json { render :show, status: :created, location: @category }
else
format.html { render :new }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
-- # POST /categories
# POST /categories.json
def create
category = Category.new(category_params)
parent=Category.find(#{params[:parent_id]})
category.move_to_child_of(parent)
respond_to do |format|
if cat.save
format.html { redirect_to admin_categories_path, notice: 'Category was successfully created.' }
format.json { render :show, status: :created, location: @category }
else
format.html { render :new }
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/68a06a4a-8920-4834-ad90-6432873c56a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment