Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

No route matches {:action=>"edit", :controller=>"*

$
0
0
*SOLVED*


In honor of the new vulnerability patch for all versions of rails, I've decided to upgrade an app of mine from 3.0 to 3.1 and then 3.2. I'm having a problem with my users#show page no longer working. It seems that the problem code has something to do with the Person model I created a long time ago (I wanted each user to be able to have multiple persons on their account).

(view.html.erb)
		<% @persons.each do |person| %>
		  <tr>
                    .
                    .
                    .
		    <td><%= link_to 'Edit', edit_person_path(person) %></td>
		  </tr>
		<% end %> 



(`rake routes` output)
.
.
.
{:action=>"edit", :controller=>"persons"}
                                          person GET    /persons/:id(.:format) 
.
.
.




(routes.rb)
  resources :persons



(config/initializers/inflections.rb)
ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'person', 'persons'
end



(persons_controller.rb)
class PersonsController < ApplicationController
  skip_before_filter :authenticate
  
  def new
    @person = Person.new #last
    
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @news_blast }
    end
  end
  
  def create
    #@person = Person.new(params[:person])
    @user = User.where(:id => params[:person][:user_id] ).first
    
    #make sure the user being edited is the current user
    if current_user != @user
      flash[:error] = "You don't have access to this user's persons"
      redirect_to "/"
      return
    end
    
    if current_user.has_password?(params[:password])  # if they had the password correct...
      current_user.password = params[:password]  # then set the password in current_user... i guess...
    else
      flash[:error] = "You had the wrong password."  # or die
      redirect_to @user
      return
    end
    
    current_user.persons.create(params[:person])
    
    if current_user.save # current_user.update_attributes(:person => params[:person])
      # sign_in @user
      flash[:success] = "Person successfully created!"
      
      redirect_to @user
    else
      flash[:error] = current_user.errors
      redirect_to @user
    end
  end

  
  # DELETE /persons/1
  # DELETE /persons/1.xml
  def destroy
    @person = Person.find(params[:id])
    @user = User.find(@person.user_id)  # find it's parent so we know where to redirect to
    @person.destroy
    
    flash[:success] = "Person removed from account."
    
    respond_to do |format|
      format.html { redirect_to @user } # redirect_to(persons_url) }
      format.xml  { head :ok }
    end
  end
  
  def edit
    @person = Person.find(params[:id])
  end

  # PUT
  def update
    @person = Person.find(params[:id])

    respond_to do |format|
      if @person.update_attributes(params[:todo])
        format.html { redirect_to(@person, :notice => 'Person was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @person.errors, :status => :unprocessable_entity }
      end
    end
  end
end


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>