darewreck
darewreck

Reputation: 2614

Redirecting and routing Ruby on Rails

I'm still new to Ruby on Rails and I'm currently having a issue with routing and redirecting.

I have two controllers "candidate" and "survey". I'm currently viewing "canidate/editEmail.html"

http://www.otoplusvn.com/TherapistSurvey/candidates/editEmail/2

Once the submit button is clicked, the candidate's method for updating the email is executed:

  def updateEmail
    @candidate = Candidate.find(params[:id])

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

This code will update the Candidate's email in the database and redirect it. I want to redirect it to an html page called end.html.erb that is located under the view/Survey/end.html.erb. However, With the present code it will give me a

Unknown action

No action responded to show. Actions: download and lastPage

where download and lastPage are the only methods in the Survey controller. "end" is not a method defined in the survey_controller.rb, but I assumed that it would automatically jump to the end.html.erb located under views/survey

On my local machine, I'm able to get this to work with this updated code:

format.html { redirect_to :controller => "survey/end" }

But this doesn't work on the site that I loaded the ruby on rail application on. In either case, I think there is probably an easier way to do this and i'm doing this incorrectly.

I think it has to deal with the route.rb file or permission that I'm unaware of when you port a local ruby on rail application to a host.

Normally I would think that if i went directly to the file

http://www.otoplusvn.com/TherapistSurvey/survey/end

I would be able to see the page like I was able on my local machine, but I'm not able to with what I have hosted.

In general, I just want to be able to redirect (jump) to another html page indicating that the email update was done correctly and that the survey is over. This is all triggered by hitting a submit button that result in an update to the database being called an a redirect to another page. The problem being how to do the redirect correctly.

BTW: in my routes.rb I have

 map.resources :survey

Any Advice Appreciated. Thanks! D

Upvotes: 0

Views: 886

Answers (2)

mark
mark

Reputation: 10564

Add this to routes.rb

map.resources :survey, :collection => {:end => :get}

Run rake routes from terminal in the route of your application to see your routes.

Use named routes:

redirect_to survey_end_path

Upvotes: 1

shingara
shingara

Reputation: 46914

You need add all other action you want.

map.resources add only route need by ressources browsing.

So add in collection option your method end in your case

map.resources :survey, :collection => {:end => :get}

Upvotes: 1

Related Questions