开发者

Problem while creating a Record (CRUD)

开发者 https://www.devze.com 2023-03-29 00:48 出处:网络
I tried to save data in my Database using Rail 3 but i could not do that.an Error occured like this: NoMethodError in Vorlesungs#new

I tried to save data in my Database using Rail 3 but i could not do that.an Error occured like this: NoMethodError in Vorlesungs#new

in my Controller:

class VorlesungsController < ApplicationController
  def new
         @vorlesung=Vorlesung.new
  end

 def create
    @vorlesung=Vorlesung.create(params[:vorlesung])
    if @vorlesung.save
       @status_message = 'Student inserted successfully.'
    else
      render 'new'
    end
  end
end

and my View:

    <%= form_for @vorlesung do |v| %>
    Name : <%= v.text_field :Name %>    <br>
    Name de Professur : <%= v.text_field :Leiter_name %><br>
    <%= v.submit 'Speicher'%>

<% end %>

when i changed Form_for into <%= form_for @vorlesung do |v| %> an error like this occured: NoMethodError in Vorlesungs#new when Form_for remains as: <%= 开发者_开发百科form_for :vorlesung do |v| %> after clicking my submit button only the content of textboxes deleted and no other effect.Thank you very much for your help

that is my full error message:

NoMethodError in Vorlesungs#new

Showing /home/babak/Management/app/views/vorlesungs/new.erb where line #1 raised:

undefined method `vorlesungs_path' for #<#<Class:0xb5f55cc0>:0xb5f54f00>
Extracted source (around line #1):

1: <%= form_for @vorlesung do |v| %>
2:     Name : <%= v.text_field :Name %>    <br>
3:     Name de Professur : <%= v.text_field :Leiter_name %><br>
4:     <%= v.submit 'Speicher'%>

and it is my route file:

Management::Application.routes.draw do
 # get "vorlesungs/Show"
  root :to => 'vorlesungs#Show'
  match 'vorlesungs/new' =>'vorlesungs#new'
end


You haven't defined a create action in your routes.

Instead of

 # get "vorlesungs/Show"
  root :to => 'vorlesungs#Show'
  match 'vorlesungs/new' =>'vorlesungs#new'

add

resources :vorlesungs

A good guide on this is to be found here.

0

精彩评论

暂无评论...
验证码 换一张
取 消