I''ve got two forms for two different models on the same page. What I want is for one of the forms to return you to the same "new" page and not clear the data in the other form. I was hoping it would be as simple as render :action => ''new'' but no such luck. Any thoughts? Thanks, Adam -- Posted via http://www.ruby-forum.com/.
Anyone? :) -Adam -- Posted via http://www.ruby-forum.com/.
Ok, the problem is that, when you submit one form, the application does not get the data from the other form, so it cannot store it (in the session). I see 2.5 possibilities: #1: Unify the forms #2.1: Use JavaScript to duplicate the entered text into hidden fields, so form1 will submit the data from form1 and form2 and vice versa #2.2: Use AJAX to periodically update the contents of the forms and save them in the session. -- Posted via http://www.ruby-forum.com/.
Adam Bloom wrote:> I''ve got two forms for two different models on the same page. What I > want is for one of the forms to return you to the same "new" page and > not clear the data in the other form. I was hoping it would be as > simple as render :action => ''new'' but no such luck. > > Any thoughts? > > Thanks, > > AdamReally, just stick the forms together. If, say, model A''s "form" is not changed, then it won''t affect the database. It will be way easier than trying to use JS/AJAX or anything like that. -- Posted via http://www.ruby-forum.com/.
Ah! That makes sense. Thanks. -Adam -- Posted via http://www.ruby-forum.com/.
This works, but I can''t help but feel that it should be simpler... def create #this seems to be the only way to test whether a tag needs to be created unless (params[:tag][:name]) == "" @tag = Tag.new(params[:tag]) @tag.save #without this line the tag field will still have text in it. @tag = Tag.new #and without these I get an error, because render :action doesn''t run the controller action. Right? @show = Show.new(params[:show]) @show.tags = Tag.find(params[:tag_ids]) if (params[:tag_ids]) @tags = Tag.find_all render :action => ''new'' else @show = Show.new(params[:show]) @show.tags = Tag.find(params[:tag_ids]) if (params[:tag_ids]) @show.save @show.user = session[:user] if @show.save session[:user].shows << @show flash[:notice] = ''Show was successfully created.'' redirect_to :action => ''list'' else @show.destroy @tags = Tag.find_all render :action => ''new'' end end end -- Posted via http://www.ruby-forum.com/.
Oops, this is wrong:> #and without these I get an error, because render :action doesn''t run > the controller action. Right?Without the @tags assignment I get an error, because the page for "new" calls @tags. Without the @show assignments I just get empty data fields.> @show = Show.new(params[:show]) > @show.tags = Tag.find(params[:tag_ids]) if (params[:tag_ids]) > @tags = Tag.find_all > render :action => ''new'' > else ...-Adam -- Posted via http://www.ruby-forum.com/.