Hello, I got two controllers, both should create new subscriptions (the name of the model). Now the thing is how to create in case of the controller not named subscriptions_controller.rb. To avoid flooding the list I put both controllers and the view in the other controller (the one that fails) and the model itself to Pastie: http://pastie.org/899454 Long story short: why do I get „NoMethodError in StudentsController#create”, why does one controller tries to use the method from the other controller, and not his own? Thanks a lot for the reply. Peter -- 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.
Any ideas? I still can''t find out why this does not work, or how to solve. Or you guys prefer pasting code into the email instead of http://pastie.org/899454 ? Thanks a lot. And Happy Easter! -- 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.
in your link I can see: beiratkozas_controller.rb subscriptions_controller.rb but where is students_controller.rb (StudentsController) ? Dose ruby asking you the same question?:) On Apr 2, 4:04 pm, WSzP <c...-6nYcUAqTnno@public.gmane.org> wrote:> Any ideas? I still can''t find out why this does not work, or how to > solve. Or you guys prefer pasting code into the email instead ofhttp://pastie.org/899454? > Thanks a lot. And Happy Easter!-- 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.
In addition, it happens because you using <% form_for(@student) do | f| %> helper if you look in HTML code (this helper appears to) you can find that request will be send to student controller... On Apr 2, 4:15 pm, DmitryPush <dmitryp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> in your link I can see: > beiratkozas_controller.rb > subscriptions_controller.rb > > but where is students_controller.rb (StudentsController) ? > > Dose ruby asking you the same question?:) > > On Apr 2, 4:04 pm, WSzP <c...-6nYcUAqTnno@public.gmane.org> wrote: > > > Any ideas? I still can''t find out why this does not work, or how to > > solve. Or you guys prefer pasting code into the email instead ofhttp://pastie.org/899454? > > Thanks a lot. And Happy Easter!-- 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.
Hello, Thanks a lot, and here is my students_controller.rb: http://pastie.org/900218 So I had one, but forgot to paste it to pastie. Peter -- 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.
so now we can see exactly what rails told you - it is now create method in student controller. :) and why you view requesting student controller i already told you. :) On Apr 2, 4:39 pm, WSzP <c...-6nYcUAqTnno@public.gmane.org> wrote:> Hello, > Thanks a lot, and here is my students_controller.rb:http://pastie.org/900218 > So I had one, but forgot to paste it to pastie. > Peter-- 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.
You got me wrong. I can''t put the create method in the student controller. The question if, how could I use the create method from the BeiratkozasController class, while the model is NOT Beiratkozas, but Student. WSZP -- 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.
You got me wrong. I can''t put the create method in the student controller. The question if, how could I use the create method from the BeiratkozasController class, while the model is NOT Beiratkozas, but Student. WSZP -- 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 2 April 2010 21:00, WSzP <ctdd-6nYcUAqTnno@public.gmane.org> wrote:> You got me wrong. I can''t put the create method in the student > controller. > The question if, how could I use the create method from the > BeiratkozasController class, while the model is NOT Beiratkozas, but > Student.Have a look at the docs for form_for, you will see it has a url parameter which will allow you to specify the controller and action that you wish to be performed on the submit. Colin -- 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 Apr 2, 3:45 pm, DmitryPush <dmitryp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> so now we can see exactly what rails told you - it is now create > method in student controller. :) > and why you view requesting student controller i already told you. > :) > > On Apr 2, 4:39 pm, WSzP <c...-6nYcUAqTnno@public.gmane.org> wrote: > > > Hello, > > Thanks a lot, and here is my students_controller.rb:http://pastie.org/900218 > > So I had one, but forgot to paste it to pastie. > > Peter-- 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.
Thanks a lot Colin, that was my problem.
From documentation I managed to make a working form_for:
<% form_for :student, @student, :url => { :action => "create"
}, :html
=> { :method => :post, :id => "beiratkozok" } do |f| %>
This works, but I don''t understand why do I need the :student in the
front. What does it do?
On Apr 2, 11:18 pm, Colin Law
<clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>
wrote:> On 2 April 2010 21:00, WSzP <c...-6nYcUAqTnno@public.gmane.org>
wrote:
>
> > You got me wrong. I can''t put the create method in the
student
> > controller.
> > The question if, how could I use the create method from the
> > BeiratkozasController class, while the model is NOT Beiratkozas, but
> > Student.
>
> Have a look at the docs for form_for, you will see it has a url
> parameter which will allow you to specify the controller and action
> that you wish to be performed on the submit.
>
> Colin
--
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.
On 2 April 2010 21:21, WSzP <ctdd-6nYcUAqTnno@public.gmane.org> wrote:> Thanks a lot Colin, that was my problem. > > From documentation I managed to make a working form_for: > > <% form_for :student, @student, :url => { :action => "create" }, :html > => { :method => :post, :id => "beiratkozok" } do |f| %> > > This works, but I don''t understand why do I need the :student in the > front. What does it do?It is in the docs, the :student says that the object being displayed and submitted is of type student, the @student is the variable containing the student. In fact since these are the same word you do not need both, either :student or @student will work I think, though using @student is more usual I think. Having both allows the class name and variable to be different. I don''t know why you have the html options they should not be needed. I also don''t understand why this is going to the beiratkozas controller, I would have expected it to go to the students controller. I would have expected you to put :url => { :controller => ''beiratkozas'', :action => "create" } to send it to that controller. Check the html of the page (View, Page Source or similar in browser). By the way it may be a good idea to put your comments inline with the previous posts as it is then easier to follow the thread. Colin> > On Apr 2, 11:18 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 2 April 2010 21:00, WSzP <c...-6nYcUAqTnno@public.gmane.org> wrote: >> >> > You got me wrong. I can''t put the create method in the student >> > controller. >> > The question if, how could I use the create method from the >> > BeiratkozasController class, while the model is NOT Beiratkozas, but >> > Student. >> >> Have a look at the docs for form_for, you will see it has a url >> parameter which will allow you to specify the controller and action >> that you wish to be performed on the submit. >> >> Colin > > -- > 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. > >-- 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.
Thanks a lot Colin,
First of all, I''m using Rails 2.3.5. and Ruby 1.8.7.
The generated HTML looks like this: <form method="post"
id="beiratkozok" action="/beiratkozas">
The option suggested by you: <% form_for :student, @student, :url =>
{:controller => ''beiratkozas'', :action =>
"create" }, :html =>
{ :method => :post, :id => "beiratkozok" } do |f| %> gives
the very
same result, so somehow the form_for assumes that controller is
''beiratkozas''. Maybe because the path is: Views/beiratkozas/
new.html.erb to the view that contains the form_for.
And works, since I have:
map.connect ''beiratkozok'', :controller =>
''beiratkozas'', :action =>
''new''
map.connect ''hallgato/:id'', :controller =>
''beiratkozas'', :action =>
''show''
map.connect ''beiratkozas'', :controller =>
''beiratkozas'', :action =>
''create''
I know that map.resources :beiratkozas would be a more Rails like
approach, but it''s more human readable for Hungarians if I use
meaningful Hungarian words.
The html is added since I need the ID for CSS, and I wanted a
meaningful word as ID, since it makes CSS easier to read. On the other
hand :method => :post was added since I saw something like that
somewhere, and it made sense, since I want to use the POST verb in
this case. Right?
Peter
P.S.: What do you mean putting my comments inline with the previous
post? I''m simply hitting reply.
--
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 2 April 2010 22:10, WSzP <ctdd-6nYcUAqTnno@public.gmane.org> wrote:> Thanks a lot Colin, > > First of all, I''m using Rails 2.3.5. and Ruby 1.8.7. > The generated HTML looks like this: <form method="post" > id="beiratkozok" action="/beiratkozas"> > The option suggested by you: <% form_for :student, @student, :url => > {:controller => ''beiratkozas'', :action => "create" }, :html => > { :method => :post, :id => "beiratkozok" } do |f| %> gives the very > same result, so somehow the form_for assumes that controller is > ''beiratkozas''. Maybe because the path is: Views/beiratkozas/ > new.html.erb to the view that contains the form_for.Well obviously if it is a beiratkozas view it will default to sending it to that controller. I thought the whole point of the question was that you wanted to send it to a different controller. I see now that that you thought that the fact that it was a Student that it was manipulating would make it send it to that controller. That is not the case. There is no explicit link between a model and a controller as far as rails is concerned. Often a controller does manage a model of the same name but this is not necessary (as you are finding yourself). A controller can manipulate models of a different name, or several different model classes, or no model at all. Rails does not care.> > And works, since I have: > > map.connect ''beiratkozok'', :controller => ''beiratkozas'', :action => > ''new'' > map.connect ''hallgato/:id'', :controller => ''beiratkozas'', :action => > ''show'' > map.connect ''beiratkozas'', :controller => ''beiratkozas'', :action => > ''create'' > > I know that map.resources :beiratkozas would be a more Rails like > approach, but it''s more human readable for Hungarians if I use > meaningful Hungarian words. > > The html is added since I need the ID for CSS, and I wanted a > meaningful word as ID, since it makes CSS easier to read. On the other > hand :method => :post was added since I saw something like that > somewhere, and it made sense, since I want to use the POST verb in > this case. Right?The submit for a form_for will default to POST, but it does no harm to include it explicitly Colin> > Peter > > P.S.: What do you mean putting my comments inline with the previous > post? I''m simply hitting reply. > > > > -- > 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. > >-- 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.
[SOLVED!] Thanks a lot, now I do understand how this work. Your help was greatly appreciated. -- 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.