在轨道上带有红宝石的表格不起作用

时间:2015-11-30 09:57:01

标签: ruby-on-rails ruby

我们正在尝试使用Ruby on Rails为餐馆建立一个网站。

当我们尝试提交表单时,我们收到此错误:

NoMethodError in Home#bookmytable

可能是什么问题?

home_controller.rb

class HomeController < ApplicationController
    def index
    end
    def menu
    end
    def bookmytable
        @table = Table.new
    end
    def create
        @table = Table.new table_params
        if @table.save
        else
            render index
        end
    end
    private
        def table_params
           params.require(:table).permit(:name, :emailID , :nop , :datee , :timee , :message)
        end
end  

bookmytable.html.erb

<h1>Book my table</h1>

<p><%= form_for :table,url: {action: 'create'} do |f| %>

    Username <%= f.text_field :name %> <br />

    Email ID <%= f.text_field :emailID %><br/>

    No of people <%= options_for_select(:nop , [['One', 1], ['Two', 2], ['Three' , 3] , ['Four' , 4] ], 1 ) %><br/>

    Date <%= f.text_field :datee %>

    Time <%= options_for_select(:timee , [[ '08:00',1 ], ['08:30' , 2], ['09:00' , 3], ['09:30' , 4], ['10:00' , 5], ['10:30' , 6],  ['12:30' , 7], ['13:00' , 8], ['13:30' , 9], ['14:00' , 10], ['14:30' , 11], ['18:00' , 12], ['18:30' , 13], ['19:00' , 14], ['19:30' , 15], ['20:00' , 16], ['20:30' , 17], ['21:00' , 18], ['21:30' , 19], ['22:00' , 20], ['22:30' , 21]], 1) %> </br>

    Message to restaurant <%= f.text_area :message %>

    <%= f.submit "Book my table" %>

<% end %></p>

1 个答案:

答案 0 :(得分:0)

def create
    @table = Table.new table_params
    if @table.save
    else
        render index
    ***end***
end

您在渲染线后错过了一个结尾。 Ruby语法需要end关键字来结束if语句