Hi experts I tried to save data in my Database in RoR but i could not do that.No Error occured but i had no success to save data.hier is my codes: in my Controller: class VorlesungsController < ApplicationController def new @vr=Vorlesung.new end def create @vorlesung=Vorlesung.create(params[:vr]) if @vorlesung.save flash[:notice]=''ABC'' render :action => ''index'' else flash[:notice]=''DEF '' render :action => ''index'' end end end 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 %> i think that my Form_for is not in correct form because when i delete create function from the controller everythings is as before and when i changed :vorlesung in Form_for to @vr an error occured : NoMethodError in Vorlesungs#new Thank you for your help -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 19 August 2011 09:12, Babak bsn <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> def new > @vr=Vorlesung.new > endChange that to: @vorlesung=Vorlesung.new And see what effect that has. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you Michael , I did it but everythings remains as before 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Babak bsn wrote in post #1017477:> Thank you Michael , > > I did it but everythings remains as before > 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 effectPost more of the error message, and any code in the error message. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
NoMethodError in Vorlesungs#new Showing /home/babak/Management/app/views/vorlesungs/new.erb where line #1 raised: undefined method `vorlesungs_path'' for #<#<Class:0xb6009cfc>:0xb6008f3c> 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''%> Rails.root: /home/babak/Management this error occured when my new.html.erb is: <%= form_for @vorlesung do |v| %> Name : <%= v.text_field :Name %> <br> Name de Professur : <%= v.text_field :Leiter_name %><br> <%= v.submit ''Speicher''%> <% end %> and my controller is: 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> i think that my Form_for is not in correct form because when i > delete create function from the controller everythings is as > before and when i changed :vorlesung in Form_for to @vr > an error occured :This looks wrong: def create @vorlesung=Vorlesung.create(params[:vr]) What the hell is :vr? What version of rails are you using? In rails 3, you would write: <%= form_for(@vorlesung) do |v| %> Name : <%= v.text_field :name, "Name:" %> <br> Name de Professur : <%= v.text_field :leiter_name, "Leiter name:" %><br> <%= v.submit ''Speicher''%> <% end %> == With that form, rails will create name attributes for your html elements like this: name="vorlesung[name]" name="vorlesung[leiter_name]" You can verify that by doing "View Source'' in your browser after the page loads. So the name of the form_for() variable, e.g. @vorlesung, because the first part of the name attribute, and the symbol you specified for the html element, e.g. :name, becomes the subscript. As a result, in your controller you can get a hash of the all the name attributes and the corresponding values entered into the form, like this: @attributes = params[:vorlesung] which will look something like this: { :name => ''Joe'', :leiter_name => ''Blow'' } Therefore, in your controller you can do this: def create @vorlesung = Vorlesung.new(params[:vorlesung]) if @vorlesung.save ... end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Babak bsn wrote in post #1017480:> NoMethodError in Vorlesungs#new > > Showing /home/babak/Management/app/views/vorlesungs/new.erb where line > #1 raised: > > undefined method `vorlesungs_path'' for #<#<Class:0xb6009cfc>:0xb6008f3c> > Extracted source (around line #1): >I think that means you did not define the proper route in your config/routes.rb file. If you do this in your routes.rb file: SampleApp::Application.routes.draw do resources :vorlesung then rails defines a lot of what are called ''named routes'' for you. Read this: http://guides.rubyonrails.org/routing.html -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you friends,that has been solved -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.