Note that there are some explanatory texts on larger screens.

plurals
  1. POHow works a form outside the associated model's view?
    primarykey
    data
    text
    <p>I have a problem that seems very simple to me, but I can't figure out the solution. So if you can be of any help, I would appreciate that very much :-)</p> <p>First of all, I used the Devise gem to create my Users.</p> <p>Here is <strong>app/models/user.rb</strong> :</p> <pre class="lang-rb prettyprint-override"><code>class User &lt; ActiveRecord::Base before_save :default_values # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :avatar, :address, :longitude, :latitude has_many :products, dependent: :destroy has_attached_file :avatar, styles: { medium: "300x300&gt;", thumb: "50x50&gt;" }, url: "users/:id/:style/:basename.:extension", path: ":rails_root/public/assets/users/:id/:style/:basename.:extension", default_url: "users/missing/:style/missing.png" #Geokit geocoded_by :address after_validation :geocode, if: :address_changed? def default_values self.address ||= "Paris" self.geocode end end </code></pre> <p>I created a Home controller for my static pages, and my root_path is <strong>app/views/home/index.html.erb</strong> in which we can find :</p> <pre class="lang-rb prettyprint-override"><code>&lt;%= render 'new_name' %&gt; </code></pre> <p>Let's take a look at this <strong>app/views/home/_new_name.html.erb</strong> :</p> <pre class="lang-rb prettyprint-override"><code>&lt;!-- Button to trigger modal --&gt; &lt;a href="#yourName" role="button" class="btn" data-toggle="modal"&gt;OK&lt;/a&gt; &lt;!-- Modal --&gt; &lt;div id="yourName" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt; &lt;div class="modal-header"&gt; &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt; &lt;h3 id="myModalLabel"&gt;&lt;%= t('home.your_name') %&gt;&lt;/h3&gt; &lt;/div&gt; &lt;div class="modal-body"&gt; &lt;%= form_for(@current_user) do |f| %&gt; &lt;p&gt; &lt;%= f.label :name, t('name'), placeholder: t('home.your_name') %&gt; &lt;%= f.text_field :name %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= f.submit t('update'), class: "btn"%&gt; &lt;/p&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>And yes, I definitely used the bootsrap's magic ;-)</p> <p>For the record, my <strong>config/routes.rb</strong></p> <pre class="lang-rb prettyprint-override"><code>Dindon::Application.routes.draw do root to: "home#index" resources :products devise_for :users match 'users/:id' =&gt; 'users#show', :as =&gt; :user match 'users' =&gt; 'users#index' end </code></pre> <p>So, the last thing to do is configure my HomeController to give to my instance variable @current_user his new name. Here is my <strong>app/controllers/home_controller.rb</strong> :</p> <pre class="lang-rb prettyprint-override"><code>class HomeController &lt; ApplicationController def index @current_user = User.find_by_id(current_user.id) end def update @current_user.update_attributes(params[:user]) end end </code></pre> <p>But it doesn't work at all. When I click on the OK button, I have the window, I fill in the field, I click on the submit button, and it send me to the User show view, but without taking the change of name in account.</p> <p>Do you have any idea of what I did wrong ?</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