Hi, I''m new at this.. can you please help me.. the drop down menus are fine, however when i click submit the selection is not saved and it tells me that movie and type can''t be blank Here is my movie_types controller class MovieTypesController < ApplicationController before_filter :login_required, :only => [:new, :create] # GET /movie_types # GET /movie_types.xml def index @movie_types = MovieType.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @movie_types } end end # GET /movie_types/1 # GET /movie_types/1.xml def show @movie_type = MovieType.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @movie_type } end end # GET /movie_types/new # GET /movie_types/new.xml def new @movie_type = MovieType.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @movie_type } end end # GET /movie_types/1/edit def edit @movie_type = MovieType.find(params[:id]) end # POST /movie_types # POST /movie_types.xml def create @movie_type = MovieType.new(params[:movie_type]) respond_to do |format| if @movie_type.save flash[:notice] = ''MovieType was successfully created.'' format.html { redirect_to(@movie_type) } format.xml { render :xml => @movie_type, :status => :created, :location => @movie_type } else format.html { render :action => "new" } format.xml { render :xml => @movie_type.errors, :status => :unprocessable_entity } end end end # PUT /movie_types/1 # PUT /movie_types/1.xml def update @movie_type = MovieType.find(params[:id]) respond_to do |format| if @movie_type.update_attributes(params[:movie_type]) flash[:notice] = ''MovieType was successfully updated.'' format.html { redirect_to(@movie_type) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @movie_type.errors, :status => :unprocessable_entity } end end end # DELETE /movie_types/1 # DELETE /movie_types/1.xml def destroy @movie_type = MovieType.find(params[:id]) @movie_type.destroy respond_to do |format| format.html { redirect_to(movie_types_url) } format.xml { head :ok } end end end view: new.html <h1>New movie_type</h1> <%= error_messages_for :movie_type %> <% form_for(@movie_type) do |f| %> <p> <b>Type</b><br /> <%= collection_select(:type, :type_id, Type.find(:all), :id, :name)%> </p> <p> <b>Movie</b><br /> <%= collection_select(:movie, :movie_id, Movie.find (:all), :id, :title) %> </p> <p> <%= f.submit "Create" %> </p> <% end %> <%= link_to ''Back'', movie_types_path %> thank you
On Apr 24, 12:39 pm, amna <a.alhi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > I''m new at this.. can you please help me.. > the drop down menus are fine, however when i click submit the > selection is not saved and it tells me that movie and type can''t be > blank >Like the other hellers, the first parameter should be the name of the instance variable, ie ''movie_type'' in your case. Or, since you are using form_for, you could use f.collection_select and drop the first parameter altogether. Fred> Here is my movie_types controller > class MovieTypesController < ApplicationController > before_filter :login_required, :only => [:new, :create] > > # GET /movie_types > # GET /movie_types.xml > def index > @movie_types = MovieType.find(:all) > > respond_to do |format| > format.html # index.html.erb > format.xml { render :xml => @movie_types } > end > end > > # GET /movie_types/1 > # GET /movie_types/1.xml > def show > @movie_type = MovieType.find(params[:id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @movie_type } > end > end > > # GET /movie_types/new > # GET /movie_types/new.xml > def new > @movie_type = MovieType.new > > respond_to do |format| > format.html # new.html.erb > format.xml { render :xml => @movie_type } > end > end > > # GET /movie_types/1/edit > def edit > @movie_type = MovieType.find(params[:id]) > end > > # POST /movie_types > # POST /movie_types.xml > def create > @movie_type = MovieType.new(params[:movie_type]) > > respond_to do |format| > if @movie_type.save > flash[:notice] = ''MovieType was successfully created.'' > format.html { redirect_to(@movie_type) } > format.xml { render :xml => @movie_type, :status > => :created, :location => @movie_type } > else > format.html { render :action => "new" } > format.xml { render :xml => @movie_type.errors, :status > => :unprocessable_entity } > end > end > end > > # PUT /movie_types/1 > # PUT /movie_types/1.xml > def update > @movie_type = MovieType.find(params[:id]) > > respond_to do |format| > if @movie_type.update_attributes(params[:movie_type]) > flash[:notice] = ''MovieType was successfully updated.'' > format.html { redirect_to(@movie_type) } > format.xml { head :ok } > else > format.html { render :action => "edit" } > format.xml { render :xml => @movie_type.errors, :status > => :unprocessable_entity } > end > end > end > > # DELETE /movie_types/1 > # DELETE /movie_types/1.xml > def destroy > @movie_type = MovieType.find(params[:id]) > @movie_type.destroy > > respond_to do |format| > format.html { redirect_to(movie_types_url) } > format.xml { head :ok } > end > end > end > > view: new.html > <h1>New movie_type</h1> > > <%= error_messages_for :movie_type %> > > <% form_for(@movie_type) do |f| %> > <p> > <b>Type</b><br /> > <%= collection_select(:type, :type_id, Type.find(:all), :id, :name)%> > </p> > > <p> > <b>Movie</b><br /> > <%= collection_select(:movie, :movie_id, Movie.find > (:all), :id, :title) %> > </p> > > <p> > <%= f.submit "Create" %> > </p> > <% end %> > > <%= link_to ''Back'', movie_types_path %> > > thank you
Thaaaaaaaaaaaaank you =D its working now 2009/4/24 Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > > > On Apr 24, 12:39 pm, amna <a.alhi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hi, >> I''m new at this.. can you please help me.. >> the drop down menus are fine, however when i click submit the >> selection is not saved and it tells me that movie and type can''t be >> blank >> > > Like the other hellers, the first parameter should be the name of the > instance variable, ie ''movie_type'' in your case. Or, since you are > using form_for, you could use f.collection_select and drop the first > parameter altogether. > > Fred >> Here is my movie_types controller >> class MovieTypesController < ApplicationController >> before_filter :login_required, :only => [:new, :create] >> >> # GET /movie_types >> # GET /movie_types.xml >> def index >> @movie_types = MovieType.find(:all) >> >> respond_to do |format| >> format.html # index.html.erb >> format.xml { render :xml => @movie_types } >> end >> end >> >> # GET /movie_types/1 >> # GET /movie_types/1.xml >> def show >> @movie_type = MovieType.find(params[:id]) >> >> respond_to do |format| >> format.html # show.html.erb >> format.xml { render :xml => @movie_type } >> end >> end >> >> # GET /movie_types/new >> # GET /movie_types/new.xml >> def new >> @movie_type = MovieType.new >> >> respond_to do |format| >> format.html # new.html.erb >> format.xml { render :xml => @movie_type } >> end >> end >> >> # GET /movie_types/1/edit >> def edit >> @movie_type = MovieType.find(params[:id]) >> end >> >> # POST /movie_types >> # POST /movie_types.xml >> def create >> @movie_type = MovieType.new(params[:movie_type]) >> >> respond_to do |format| >> if @movie_type.save >> flash[:notice] = ''MovieType was successfully created.'' >> format.html { redirect_to(@movie_type) } >> format.xml { render :xml => @movie_type, :status >> => :created, :location => @movie_type } >> else >> format.html { render :action => "new" } >> format.xml { render :xml => @movie_type.errors, :status >> => :unprocessable_entity } >> end >> end >> end >> >> # PUT /movie_types/1 >> # PUT /movie_types/1.xml >> def update >> @movie_type = MovieType.find(params[:id]) >> >> respond_to do |format| >> if @movie_type.update_attributes(params[:movie_type]) >> flash[:notice] = ''MovieType was successfully updated.'' >> format.html { redirect_to(@movie_type) } >> format.xml { head :ok } >> else >> format.html { render :action => "edit" } >> format.xml { render :xml => @movie_type.errors, :status >> => :unprocessable_entity } >> end >> end >> end >> >> # DELETE /movie_types/1 >> # DELETE /movie_types/1.xml >> def destroy >> @movie_type = MovieType.find(params[:id]) >> @movie_type.destroy >> >> respond_to do |format| >> format.html { redirect_to(movie_types_url) } >> format.xml { head :ok } >> end >> end >> end >> >> view: new.html >> <h1>New movie_type</h1> >> >> <%= error_messages_for :movie_type %> >> >> <% form_for(@movie_type) do |f| %> >> <p> >> <b>Type</b><br /> >> <%= collection_select(:type, :type_id, Type.find(:all), :id, :name)%> >> </p> >> >> <p> >> <b>Movie</b><br /> >> <%= collection_select(:movie, :movie_id, Movie.find >> (:all), :id, :title) %> >> </p> >> >> <p> >> <%= f.submit "Create" %> >> </p> >> <% end %> >> >> <%= link_to ''Back'', movie_types_path %> >> >> thank you > > >