나는 정말로 간단한 질문이라고 생각하는 간단한 대답을 찾는 데 문제가 있습니다.Ruby on Rails : 텍스트 상자 데이터를 사용하여 다른 페이지의 양식 데이터 채우기
내가 원하는 것은 모든 종류의 텍스트 필드를 사용하여 '제목'을 검색 한 다음 사용자를 올바른 페이지로 리디렉션하여 해당 제목에 대한 정보를 입력하는 것입니다.
그래서 사용자가 '1001'을 입력하면 '1001'이라는 제목으로 이미 입력 된 데이터로 채워지는 양식으로 이동하게됩니다.
그래서 나는 여기에 내가 알아 내기 위해 노력하고있어 것 같아요 :
은 하나의 변수가 이제까지 @ subject.subject_id 검색 할 것이라는 점을 가정합니다.텍스트 필드의 변수를 저장하여 해당 변수를 link_to 필드에 전달하면 전체 페이지에 해당 주제 정보가 채워지는 것을 어떻게 알 수 있습니까? - 내가 '
여기def update
@subject = Subject.find(params[:id])
respond_to do |format|
if @subject.update_attributes(params[:subject])
format.html { redirect_to @subject, notice: 'Subject was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @subject.errors, status: :unprocessable_entity }
end
end
end
...
def populate_values
@subject_id = params[:subject_id]
redirect_to screening_path(@subject_id)
end
end
내 경로 코드의 일부는, 멍청한 놈되는 실례하시기 바랍니다있다
subjects_controller.rb :
나는 (populate_values)와 함께 새로운 게임 컨트롤러 요소를 추가 한 여전히 무엇이 무엇을 유발하는지 알아 냈습니다.
routes.rb
#resources :subjects, only: [:new, :create, :destroy] # Copied th
resources :subjects
...
match '/subjects', to: 'subjects#show'
match '/newsubject', to: 'subjects#new'
match '/subjects', to: 'subjects#index'
match '/showsubject', to: 'subjects#show'
match '/editsubject', to: 'subjects#edit'
match '/screening', to: 'subjects#screening'
#match '/populate_values', to: 'subjects#screening' #Just trying to figure out things.
그리고 여기이 값은 사용자가 입력 될 위치에서 내보기입니다. 나는 내가 실제로 잘못하고있는 것이 무엇이든지간에이 형태에서 유래 할 가능성이 가장 높다고 생각합니다. 또한이 양식은 주제보기가 아닌 사용자보기 내에 있습니다 (중요하다면). 어떤 도움을 크게 감상 할 수
<% provide(:title, @user.name) %>
<div class="row">
<aside class="span4">
<section>
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
<hr>
</section>
<div class="user_profile">
<h2>Data Entry</h2>
<body>
<p><%= link_to "Add a new Patient", newsubject_path %></p>
<p><%= link_to "View Patients", subjects_path %></p>
<%= form_tag('/subjects_controller/populate_values') do %>
<%= text_field_tag 'subject_id' %>
<div class="btn btn-link">
<%= submit_tag "Screening Log" %>
</div>
<% end %>
</body>
</div>
</aside>
</div>
보기/사용자/show.html.erb.
나는 현재이 subject.subject_id를 인식하지 못합니다 그러나
<%= link_to "Screening", screening_path, :subject_id => subject.subject_id, :class => 'btn btn-mini' %>
와 장난 해요 1.
편집. "정의되지 않은 지역 변수 또는 메소드 제목".
귀하의 심사 경로는 ID를받지 못하지만 귀하의 리디렉션이 ID를 전달하고 있습니다 - redirect_to screening_path (@ 제목 _id) 내가 빠진 것이 있습니까? 그렇지 않으면 <% = f.text_field : subject_id, : value => params [: id] – fatfrog