I have nested resources like that :
resources :cards do
resources :teammates
resources :formata, only: [:index, :show]
end
- I use formata#show to render an alternative card#show
- Cards has_many teammates
QUESTION : I would like to display all the infos available inside Cards table (city, place, ...), and the infos of the Teammates belonging to the card (firstname, lastname) => in the formata#show view.
I do not know how to set the strong parameters to work well.
For the moment I have in formata controller :
class FormataController < ApplicationController
before_filter :authenticate_crafter!
before_action :set_card, only: [:show]
def index
render ("formata/show")
end
def show
@card = Card.find(params[:card_id])
@teammates = Teammates.where(card_id: @card).take!
end
private
def set_card
@card = Card.find(params[:card_id])
end
def formata_params
params.require(:card).permit(:content, :city, :place)
end
end
Triggered with url like this :
http://www.appname.com/cards/:id_card/formata
And my view formata/show.html.erb contains:
City <%= @Card.city %>
Place <%= @Card.place %>
Rendering view error:
undefined method `city' for nil:NilClass
None of my 2 variables @card & @teammates work in formata#show. And work well in #teammates (same level of nest).
Any help would be much appreciated. Thank you