ビューから別のビューに値を渡して、別のフォームをレール3に挿入するにはどうすればよいですか?その後、クライアント・インデックス・ビューで、私は、検索テキストフィールドを配置ビューから別のビューに値を渡して、別のフォームをレールに挿入する方法3
私はクライアントと販売足場を生成し、:
私はここで、これを実現する方法について混乱ビットをレールとIMに新しいですが、私のscenerioですクライアントを検索し、その下にレンダリングします。各クライアントにはSaleというボタンがあり、クリックするとnew_sales_pathにリダイレクトされ、名前、住所、ID、電話番号などのクライアントの値がフォームのフィールドに自動的に入力されます。
私がしたいことは次のとおりです。 ボタンセールをクリックしてからnew_salesフォームをポーリングするときにクライアントの情報を渡したいとします。
だから私は、インデックス・クライアントでこのコードを持っているが表示:私のクライアントと私はラインを持って販売コントローラで
def sale_button
@sale_button = client
end
::私は自分のアプリケーションのヘルパーで
<%= form_tag clientes_path, :method => 'get', :id => "clientes_search", :class => "form-search" do %>
<p>
<%= text_field_tag :search, params[:search], :class => "input-medium search-query" %>
<%= submit_tag "Search", :name => nil, :class => "btn" %>
<% @clients.each do |client| %>
<tr>
<td><%= client.id %></td>
<td><%= client.email %></td>
...
...
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_client_path(client), :class => 'btn btn-mini' %>
<%= link_to "Sale", new_sale_path, :action => 'sale_button', :id => 'sale_button', :class => 'btn btn-mini' %>
<% end %>
</tr>
<% end %>
を
helper_method :sale_button
私の新しい販売ビューで私は
<div id='sales'>
<%= simple_form_for @sale, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :client, :label => "Client ID", :required => true, :as => :string, :input_html => { :value => @sale_button.id } %>
...
...
<% end %>
私は正しい方法で行っているのか、何か不足しているものがあれば、助けや歓迎を歓迎します。
Imを使用して、レール3.2ところで
販売コントローラ
class SalesController < ApplicationController
before_filter :authenticate_user!
helper_method :sort_column, :sort_direction
helper_method :boton_venta
# GET /sales
# GET /sales.json
def index
@sales = Sale.search(params[:search]).order(sort_column + " " + sort_direction).paginate(:per_page => 10, :page => params[:page])
@lista_porcentajes = Porcentaje.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @sales }
format.js
end
end
# GET /sales/1
# GET /sales/1.json
def show
@sale = Sale.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @sale }
end
end
# GET /sales/new
# GET /sales/new.json
def new
@sale = Sale.new
@client = Client.find(params[:client_id])
respond_to do |format|
format.html # new.html.erb
format.json { render json: @sale }
format.json { render json: @client }
end
end
# GET /sales/1/edit
def edit
@sale = Sale.find(params[:id])
end
# POST /sales
# POST /sales.json
def create
@sale = Sale.new(params[:sale])
respond_to do |format|
if @sale.save
format.html { redirect_to @sale, notice: 'Sale was successfully created.' }
format.json { render json: @sale, status: :created, location: @sale }
else
format.html { render action: "new" }
format.json { render json: @sale.errors, status: :unprocessable_entity }
end
end
end
# PUT /sales/1
# PUT /sales/1.json
def update
@sale = Sale.find(params[:id])
respond_to do |format|
if @sale.update_attributes(params[:sale])
format.html { redirect_to @sale, notice: 'Sale was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @sale.errors, status: :unprocessable_entity }
end
end
end
# DELETE /sales/1
# DELETE /sales/1.json
def destroy
@sale = Sale.find(params[:id])
@sale.destroy
respond_to do |format|
format.html { redirect_to sales_url }
format.json { head :no_content }
end
end
private
def sort_column
Sale.column_names.include?(params[:sort]) ? params[:sort] : "id"
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
end
end
routes.rbを
Puntodeventa::Application.routes.draw do
resources :empresas
resources :cliente_grupo_empresas
devise_for :users, :admin_empresas, :empresa_users, :cliente_users, :admins
resources :relacion_porcentaje_grupoempresas
resources :relacion_grupo_empresas
resources :porcentajes
resources :categoria_empresas
resources :grupo_empresas
resources :sales
resources :cliente_empresas
resources :clients
get "home/index"
resources :productos
root :to => "home#index"
すくい経路
sales GET /sales(.:format) sales#index
POST /sales(.:format) sales#create
new_sale GET /sales/new(.:format) sales#new
edit_sale GET /sales/:id/edit(.:format) sales#edit
sale GET /sales/:id(.:format) sales#show
PUT /sales/:id(.:format) sales#update
DELETE /sales/:id(.:format) sales#destroy
あなたが提案修正と
<div id='sales'>
<%= simple_form_for @sale, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :client, :label => "Serial del cliente", :required => true, :as => :text, :input_html => { :value => ' ' } %>
<%= f.association :client, :label_method => :nombre, :label_value => :id, :required => true, :as => :string %>
<%= f.association :porcentaje, :label_method => :porcentaje, :value_method => :porcentaje, :required => true %>
<%= f.input :monto_venta, :required => true, :as => :string %>
<% if current_user.try(:admin?) %>
<%= f.association :empresa, :label_method => :nombre, :value_method => :id, :required => true %>
<% else %>
<% f.association :empresa, :disabled => true, :input_html => { :value => current_user.empresa_id } %>
<% end %>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
sales_path, :class => 'btn' %>
</div>
<% end %>
</div>
新しい販売ビューnew.html.erb販売でレンダリングされている
<%- model_class = @sale.class -%>
<h1><%=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human,
:default => "New #{model_class.model_name.human}") %> </h1>
<%= render :partial => 'form' %>
フォームnew.html.erbの
販売。
オハイオ州オクラホマ、はい私はあなたが言っていることを理解していますが、私は自分自身を正しく説明していないかもしれない、私に試してみましょう。私は2つのテーブル、クライアントと売上高を持って、私が述べた販売ボタンは、クライアントのインデックスビュー "app/views/clients/index.html.erb"にあり、それはすべてのクライアントを表示し、各クライアントは販売ボタンを持っています。このボタンを押すと、ユーザーは新しい販売ビュー「app/views/sales/new.html.erb」にリダイレクトされ、これはうまく動作し、それを私にリダイレクトしてページを表示します。私はできないことは、特定のクライアントのIDを新しいセールスビューに渡すことです。私はそれを行う方法を知らないのです... – user1350443
彼らは異なるコントローラ "app/controllers/clients_controller.erb"と "app/controllers /sales_controller.erb "と入力します。 販売ボタンが表示されているクライアントのインデックスビューを貼り付けて、私が何を話しているのか知っています。 – user1350443
これを試してみてください。クライアントIDをこのリンクのパラメータとして渡しています。 <%= link_to "Sale"、{:controller => "sales"、:action => "new"、:client_id => client.id}、{:class => 'btn btn-mini'}%>今あなたのセールリンクとしてこれを使用してください。それをクリックして、ブラウザのアドレスバーにアクセスしたURLをクリックしてコピー&ペーストします。 – beck03076