Рельсы STi с 1 до 1 ассоциацией

Вы также можете использовать событие нажатия кнопки:


    
        
    

protected void MyButtonClick(object sender, System.EventArgs e)
{
    //Get the button that raised the event
    Button btn = (Button)sender;

    //Get the row that contains this button
    GridViewRow gvr = (GridViewRow)btn.NamingContainer;
} 

ИЛИ

Вы можете сделать это, чтобы получить данные:

 void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
 {

    // If multiple ButtonField column fields are used, use the
    // CommandName property to determine which button was clicked.
    if(e.CommandName=="Select")
    {
      // Convert the row index stored in the CommandArgument
      // property to an Integer.
      int index = Convert.ToInt32(e.CommandArgument);    

      // Get the last name of the selected author from the appropriate
      // cell in the GridView control.
      GridViewRow selectedRow = CustomersGridView.Rows[index];
    }
}

и Button в gridview должны иметь такую ​​команду и обрабатывать событие rowcommand:



        
          
        
  

Проверить полный пример в MSDN

-1
задан stuckoverflow24 3 March 2019 в 15:33
поделиться

2 ответа

Почему вы используете Модель в качестве названия модели? Я думаю, что вы ищете полиморфные отношения https://guides.rubyonrails.org/association_basics.html#polymorphic-associations

Но без дополнительной информации о ваших моделях мы можем ' т лучший ответ. Возможно, вы захотите взглянуть на эту статью о STI против полиморфных отношений

0
ответ дан lacostenycoder 3 March 2019 в 15:33
поделиться

Из https://edgeguides.rubyonrails.org/active_record_migrations.html

rails generate migration AddUserRefToProducts user:references

создается

class AddUserRefToProducts < ActiveRecord::Migration[5.0]
  def change
    add_reference :products, :user, foreign_key: true
  end
end
[ 117] Эта миграция создаст столбец user_id и соответствующий индекс. Дополнительные параметры add_reference см. В документации API.

Итак, в вашем случае:

rails generate migration AddStudentRefToInfo student:references

, что сгенерирует следующую миграцию:

class AddUserRefToProducts < ActiveRecord::Migration[5.0]
  def change
    add_reference :info, :student, foreign_key: true
  end
end

Обратите внимание, что предполагается, что ваша модель «Информация» хранится в таблице. называется «информация». Это может быть «информация».

0
ответ дан Mark 3 March 2019 в 15:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: