ruby on rails - New action not working, routing error when calling Category.new() -


i had custom reorder action working created new items through ajax. after making changes other parts of site new action doesn't work.

when go page categories/reorder, or categories/new loads page properly, if comment out line @category = category.new().

as try set @category = category.new(), @category = category.new(:parent_id => params[:parent_id]), or @category = category.new gives me error message:

no route matches {:action=>"edit", :controller=>"categories", :id=>#<category _id: 515ee18c10188f64fb000001, created_at: nil, updated_at: nil, deleted_at: nil, ancestry: nil, user_id: nil, name: nil, description: nil, image: nil, lock: nil, _slugs: []>} 

i dropped database in case there entry somehow gave me error, on logging in again still gives me message.

here's routes file:

  match '/auth/:provider/callback' => 'sessions#create'   match '/auth/failure' => 'sessions#failure'   match '/signout' => 'sessions#destroy', :as => :signout   match '/signin' => 'sessions#new', :as => :signin    match "reorder/symbols" => "categories#reorder", :via => :get, :as => :reorder_symbols   resources :pages     resources :blocks       collection { post :sort }     end   end     'symbols/:id/search/', to: 'categories#search', as: :sift_meanings    "logout" => "sessions#destroy", :as => "logout"   "login" => "sessions#new", :as => "login"   "signup" => "users#new", :as => "signup"   resources :users   resources :sessions   match "meanings/:id/delete" => "meanings#destroy", :via => :get, as: :delete_meaning    match "symbols/gallery/:id" => "categories#gallery", :via => :get   resources :symbols, :as => :categories, :controller => :categories     resources :meanings     collection {post :sort}   end    root :to => 'categories#index' 

controller file:

class categoriescontroller < applicationcontroller   helper :lego   helper :meanings    def index     @categories = category.all     if params[:id]       @categories = category.find(params[:id])                      #if params[:id]       @categories = @categories.subtree.arrange(:order => 'name')     elsif params[:view] == "alpha"       @alphabet   = category.all.group_by{|c| c.name[0]}       @see_kids   = false       @categories = @categories.sort(:name => "asc")                            if !params[:letter]       @categories = @categories.where(name: eval("/^#{params[:letter]}/i")).sort(:name => "asc")     if params[:letter]     else       # @categories = category.all       @categories = @categories.arrange(:order => 'name')               #if params[:view] != "list"     end        respond_to |format|       format.html # index.html.erb       format.js       format.json { render json: @categories }     end   end    def reorder     if rails.env != "production" && !request.xhr?       flash[:info] = "currently in #{rails.env} mode."     end     @categories = category.arrange(:order => 'name')     # @category = category.new     @next = category.count     respond_to |format|       format.html # index.html.erb       format.js       format.json { render json: @categories }     end   end    def sort     params[:category].each |id, attr|       thiscat = params[:category][id]       @category = category.where(:_id => id).first       if thiscat.nil? || thiscat == 'null'         @category.parent_id = nil       else         @category.parent_id = thiscat.to_s       end       @category.save     end   end    def gallery     @categories = category.arrange(:order => 'name')     @category = category.find(params[:id])     @siblings = category.siblings_of(params[:id])     respond_to |format|       format.html # index.html.erb       format.js       format.json { render json: @category }     end   end     def show      @categories = category.arrange(:order => 'name')      @category   = category.find(params[:id])      @updater    = user.find(@category.user) || nil      @siblings   = category.siblings_of(params[:id])      @meanings   = @category.meanings #meaning.where(:category_id => params[:id])      @belief_list    = []      @culture_list   = []      @contributors   = []      @connotations   = []      meaning in @meanings        belief in meaning.beliefs          @belief_list << belief         end        culture in meaning.cultures          @culture_list << culture        end        @connotations << meaning.connotation        @contributors << meaning.user      end      @beliefs      = @belief_list.uniq      @cultures     = @culture_list.uniq      @contributors = @contributors.uniq      @connotations = @connotations.uniq       respond_to |format|        format.html # show.html.erb        format.js        format.json { render json: @category }      end    end    def search     @categories = category.arrange(:order => 'name')     @category = category.find(params[:id])      @meanings = @category.meanings     @meanings = @meanings.where(:beliefs => params[:beliefs])         if params[:beliefs]     @meanings = @meanings.where(:cultures => params[:cultures])       if params[:cultures]     @meanings = @meanings.where(:connotation => params[:connotation]) if params[:connotation]     @meanings = @meanings.where(:user => params[:user])               if params[:user]       end     # /categories/new   # /categories/new.json   def new     @category = category.new(:parent_id => params[:parent_id])     # @category.photo.build     respond_to |format|       format.html # new.html.erb       format.js       format.json { render json: @category }     end   end    # /categories/1/edit   def edit     @category = category.find(params[:id])   end    # post /categories   # post /categories.json   def create     @category = category.new(params[:category])     @category.user = current_user     @categories = category.arrange(:order => :created_at)     if @category.save       flash[:success] = "<h4><i class=icon-ok></i> '#{@category.name}' created.</h4>"     end     respond_to |format|       if @category.save         format.html { redirect_to @categories, notice: 'category created.' }         format.js         format.json { render json: @categories, status: :created, location: @category }       else         format.html { render action: "new" }         format.js          format.json { render json: @category.errors, status: :unprocessable_entity }       end     end   end    # put /categories/1   # put /categories/1.json   def update     @category = category.find(params[:id])     @category.user = current_user     flash[:success] = "<h4><i class=icon-ok></i> #{@category.name} updated.</h4>"     respond_to |format|       if @category.update_attributes(params[:category])         format.html { redirect_to @category}         format.js         format.json { head :no_content }       else         format.html { render action: "edit", error: "unable update '#{@category.name}'", status: :unprocessable_entity }         format.json { render json: @category.errors, status: :unprocessable_entity }       end     end   end    # delete /categories/1   # delete /categories/1.json   def destroy     @category = category.find(params[:id])     @category.destroy     flash[:alert] = "<h4><i class=icon-warning-sign></i> warning. have deleted category '#{@category.name}'.</h4>".html_safe       respond_to |format|       format.html { redirect_to categories_url }       format.json { head :no_content }       format.js      end   end    def has_sidebar?     self.has_children?   end private  end 

the other thing note, found on reverting older working version have restart server because of less twitter bootstrap variable not being set right. don't think should affecting this.

if follow stack trace, show error is. since mentioned happens when add call @category = category.new, can think because using @category create edit link. since @category new object, you'll errors. try @ view files edit links can found.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -