, 나는 양식을보기에서 양식 제출 후에는 sites_controller.rb
레일 : 액세스 매개 변수 내 레일 3.2 프로젝트에서
def create
@site = Site.new(params[:site])
respond_to do |format|
if @site.save
format.html { redirect_to @site }
else
format.html { render action: "new" }
end
end
end
에 그런
app/views/sites/
<%= form_for(@site) do |site_form| %>
...
<div class="field">
<%= site_form.label :hash_name %><br />
<%= site_form.text_field :hash_name %>
</div>
...
<div class="actions">
<%= site_form.submit %>
</div>
<% end %>
create
기능에 new.html.erb
에 새 사이트를 만들 수 있습니다
사용자가 제출 한 후 사용자가 방금 제출 한 hash_name
을 표시하려고합니다. show.html.erb
You just put in <%= params[:hash_name] %>.
그러나 액세스 params[:hash_name]
은 작동하지 않습니다. 어떻게 접근 할 수 있습니까?
오케이,'@ site'에서 바로 가져옵니다. 어쨌든'hash_name'을 매개 변수로 전달하는 방법은 무엇입니까? 나는 redirect_to @site, : hash_name => params [: hash_name]'을 시도한 다음'params [: hash_name]에 접근하면 비어있게된다. –
매개 변수로 전달할 필요는 없지만 이렇게하려면 생성 된 경로에 추가해야합니다. 'redirect_to site_path (@site, hash_name : hash_name)'(또는 당신의 라우트가 호출 된 곳). – sevenseacat
모든 권리 덕분에! –