Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving data into a model from another controller
    primarykey
    data
    text
    <p>I have a controller, which saves fine for that specific controller and model (accesspoint). However, i want to save a particular data into another model (radhuntgroup) - which i do not know how.</p> <pre><code> def create @accesspoint = Accesspoint.new(params[:accesspoint]) @accesspoint.user_id = current_user.id o = [('a'..'z'), ('1'..'9'), ('A'..'Z')].map { |i| i.to_a }.flatten @accesspoint.secret = (0...30).map{ o[rand(o.length)] }.join respond_to do |format| if @accesspoint.save format.html { redirect_to accesspoints_path, notice: 'Access Point has been added.' } format.json { render json: @accesspoint, status: :created, location: @accesspoint } else format.html { render action: "new" } format.json { render json: @accesspoint.errors, status: :unprocessable_entity } end end end </code></pre> <p>the above looks fine for accesspoint controller and model (saves all the parameters from form into the accesspoint table) however, i want to save one particular data into another field into the radhuntgroup table.</p> <p>accesspoint view.</p> <pre><code>%= simple_form_for @accesspoint, :html =&gt; { :class =&gt; 'form-horizontal' } do |f| %&gt; &lt;div class="control-group"&gt; &lt;div class="controls"&gt; &lt;%= f.input :shortname, :label =&gt; false, :autofocus =&gt; true, :placeholder =&gt; 'Access Point Name', :hint =&gt; 'example: quadifi_hotspot' %&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="form-actions"&gt; &lt;%= f.submit nil, :class =&gt; 'btn btn-primary' %&gt; &lt;%= link_to t('.cancel', :default =&gt; t("helpers.links.cancel")), accesspoints_path, :class =&gt; 'btn' %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>in this case, i hope to duplicate the "shortname" column in the accesspoint table into the radhuntgroup table in the "groupname" column. - which i am looking at using the controller to do this.</p> <p>If i were to do it in PHP for example, this would be a lot easier but i am dealing with legacy databases which most parts of backend is already "hardcoded" this way and i cannot fully follow the conventions.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload