سؤال

I have an already existing Artist model and controller but didn't scaffold it and get views because I don't want to be them created through a form.

I want to add a show.html.erb file for the Artist view though so that a user can view a page for a specific artist. Is there an easy way to manually do this by creating a json file similar to what is created when one scaffold's something? I tried to create one and then make a view similar to what it would look like had I scaffolded, but kept getting a lot of undefined method errors.

هل كانت مفيدة؟

المحلول

To clarify, you have a Artist model and controller and want a show.html.erb file? Something like this should work. In your routes file, add a line that refines which actions you want artists to have:

resources :artists, only: [:show] #and any other actions you want inside the brackets

In your artists controller:

# GET /artists/1
# GET /artists/1.json
def show 
   #whatever info needs to be shared with the view
   @artist = Artist.find(params[:id])
end

Then create a file inside app/views/artists and call it show.html.erb

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top