Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7777721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:12:51+00:00 2026-06-01T18:12:51+00:00

Models in my app class Category < ActiveRecord::Base has_many :dishes, :dependent => :destroy end

  • 0

Models in my app

class Category < ActiveRecord::Base
  has_many :dishes, :dependent => :destroy
end

class Dish < ActiveRecord::Base
  attr_accessible :assets_attributes
  belongs_to :category
  has_many :assets
  accepts_nested_attributes_for :assets, :allow_destroy => true
end

class Asset < ActiveRecord::Base
  belongs_to :dish
  has_attached_file :asset, :styles => { :large => "640x480", :medium => "300x300>", :thumb => "100x100>" }
end

In Gemfile

source 'http://rubygems.org'
gem 'rails', '3.0.11'
gem 'sqlite3', '1.3.3'
gem 'paperclip'

app/controllers/dishes_controller.rb

class DishesController < ApplicationController

  def new
    @category = Category.find(params[:id])
    @dish = @category.dishes.new(:category_id => params[:id])
    @dish.assets.build    
    @title = "Create dish"
    respond_to do |format|
      format.html # new.html.erb
      format.json  { render :json => @category }
    end
  end

  def create
    @category = Category.find(params[:category_id])
    @dish = @category.dishes.create(params[:dish])
    respond_to do |format|
      format.html { 
        flash[:success] = "Dish created successfully!"
        redirect_to(@category) }
      format.json  { render :json => @category }
    end
  end

end

app/views/categories/show.html.erb

<p><%= notice %></p>

<h1> Category Details </h1>

...

<hr />

<h2>Dishes</h2>

<table>
  <tr>
    ...
  </tr>

  <%= render @category.dishes %>

</table>

<%= link_to 'New Dish', newdish_path(:id => @category.id) %>

app/views/dishes/new.html.erb

<h1>New Dish</h1>

<%= render 'form' %>

app/views/dishes/_form.html.erb

<%= form_for([@category, @dish]), :html => { :multipart => true } do |f| %>
...# Here the fields for dishes table will come
  <div class="field">
    <h4>New Files</h4>
      <% f.fields_for :assets do |asset_fields| %>
        <% if asset_fields.object.new_record? %>
      <p>
        <%= asset_fields.file_field :asset %>
      </p>
    <% end %>
      <% end %>
    <h4>Old Files</h4>
      <% f.fields_for :assets do |asset_fields| %>          
        <% unless asset_fields.object.new_record? %>
      <div class="thumb">
        <%= link_to image_tag(asset_fields.object.asset.url(:thumb)), asset_fields.object.asset.url(:original) %>
        <%= asset_fields.check_box :_destroy %>         
      </div>    
    <% end %>
      <% end %>
  </div>
...
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

While trying to run these code I got an error

SyntaxError in Dishes#new

Showing /home/ragunathjawahar/Desktop/PROJECT/karaikudi-before-send/app/views/dishes/_form.html.erb where line #1 raised:

/home/ragunathjawahar/Desktop/PROJECT/karaikudi-before-send/app/views/dishes/_form.html.erb:1: syntax error, unexpected tASSOC, expecting keyword_end
...r([@category, @dish]), :html => { :multipart => true } do |f...
...                               ^
/home/ragunathjawahar/Desktop/PROJECT/karaikudi-before-send/app/views/dishes/_form.html.erb:1: syntax error, unexpected keyword_do_block, expecting keyword_end
...ml => { :multipart => true } do |f| @output_buffer.safe_conc...
...                               ^
/home/ragunathjawahar/Desktop/PROJECT/karaikudi-before-send/app/views/dishes/_form.html.erb:51: syntax error, unexpected keyword_ensure, expecting $end

How to solve this problem?

Thanks in advance…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:12:52+00:00Added an answer on June 1, 2026 at 6:12 pm

    Correct this line first and tell

        <%= form_for([@category, @dish], :html => { :multipart => true }) do |f| %>
    

    use this line for create dish

                @dish = Dish.create!(:dishCode => params[:dish][:dishCode] ,:name => params[:dish][:name])
    

    instead of

            @dish = @category.dishes.create(params[:dish])   
    

    but first check params[:dish][:dishCode] give you value or not.

    And chill…….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name
In my Rails 2.3.2 app I have 2 models: class Post has_many :approved_comments, :class_name
I have a ruby (1.9.3) on rails (3.1) app where: app/models/list.rb class List <
Here's part of my Django app's models.py : class Person(models.Model): birth_year = WideYear(null=True, blank=True)
I'm trying to add images to my models in my Django app. models.py class
I think this is a common scenario. I'm defining class models of my app,
I have 2 models, Post and Category: class Category(models.Model): # some fields class Post(models.Model):
Model: app.models.Category = Ext.regModel(Category, { fields: [ { name: 'CategoryId', type: 'int' }, {
I have these models: class App(models.Model): name = models.CharField(max_length=100) class ProjectA(models.Model): name = models.CharField(max_length=100)
class Category(models.Model): name = models.CharField(max_lenth=50) class SubCatergory(models.Model): parent_category = models.ForeignKey(Category) name = models.CharField(max_length=100) class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.