Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Matt Horan
Matt Horan
138 Points

Rails basic form issue

I am attempting to create a basic form within rails. I have the form running and can fill in details and submit data, which I can see in the terminal log is being saved. The issue I am having is when I attempt to display the data saved I get the following message " "Couldn't find Editprofile with 'id'=show" and it points to an issue with my show controller.

class EditprofilesController < ApplicationController

def index
    @editprofile = Editprofile.all
end

def show
    @editprofile = Editprofile.find (params[:id])
end

def new
    @editprofile = Editprofile.new
end

def create
@editprofile = Editprofile.new(editprofile_params)

if @editprofile.save
    redirect_to editprofiles_url
else
    render 'new'
end
end 

def editprofile_params
params.require(:editprofile).permit(:image,:fristname, :lastname, :country,) 
end 

end

I just can not work out what the issue is. Any help would be greatly appreciated.

Kind Regards

Matt

1 Answer

Daniel Samer
Daniel Samer
14,473 Points

Are you trying to access your page with http://whatever.domain/editprofiles/show ?

If yes you have to access it with http://whatever.domain/editprofiles/1 ( While 1 being the id of your Editprofile object).

Matt Horan
Matt Horan
138 Points

Hi Daniel, thank you so much for replying.

I am pretty new to rails and have been following some instructions on a website called www.guides.rubyonrails.org/getting_started.html and it has a section on how to create a basic form in rails.

Within Views/Editprofiles/New I have a form created with the following code. I have taken the ruby brackets out so it will display. For some reason it wont display it here.

form_for :editprofile, url: editprofiles_path do |f|

f.label :fristname 
f.text_field :fristname 

  f.label :lastname
  f.text_field :lastname

I checked the source code on the web page and the form action is pointing at editprofiles. The form saved the data no problem.

My routes are set as resources :editprofiles so that looks ok.

So that just leaves my controller settings and honestly its doing my head in as to what I am doing wrong :) I know its something pretty simple but I can't work out why I can't display this information at the following view

http://localhost:3000/editprofiles/show

It just displays ActiveRecord::RecordNotFound in EditprofilesController#show Couldn't find Editprofile with 'id'=show

If you can help solve this it would be really appreciated :) It would also ensure I don't lose my sanity!

Regards

Matt