form-for

Rails not editable text field

自古美人都是妖i 提交于 2019-12-02 17:22:24
I have a form_for written in the following manner: <div class="field"> <%= location.label :city %> <%= location.text_field :city, :disabled=>true%> </div> <div class="field"> <%= location.label :country %> <%= location.text_field :country, :disabled=>true%> </div> As you can see the 2 textfield are disabled because they are autofilled by a jquery function and I don't want let the user handle them. The problem is that in this way, the view doesen't pass that parameters to the controller because are disabled !!! Is there any other way to pass not editable text_field to the controller, taking

form_for being submitting by 2 links, how to I tell which was used when I am back in the controller?

断了今生、忘了曾经 提交于 2019-12-02 17:05:37
问题 I putting a form together, but for design reason the form must be submitted by a link. I found out how to perform that: = link_to_function "Next >>", "$(this).up('form').submit()" This will do, and I can create many link with this no problem. However I don't know how to distinguish which link was used to bring me back to the controller ? I need to perform slightly different depending on the link... Any idea ? I have tried to embed some javascript, etc. but I could not figure it out. Thanks,

form_for being submitting by 2 links, how to I tell which was used when I am back in the controller?

ぐ巨炮叔叔 提交于 2019-12-02 11:20:33
I putting a form together, but for design reason the form must be submitted by a link. I found out how to perform that: = link_to_function "Next >>", "$(this).up('form').submit()" This will do, and I can create many link with this no problem. However I don't know how to distinguish which link was used to bring me back to the controller ? I need to perform slightly different depending on the link... Any idea ? I have tried to embed some javascript, etc. but I could not figure it out. Thanks, Alex = link_to_function "Next >>", "$('#hidden_field').value = 1;$(this).up('form').submit()" = link_to

Keep params after render Ruby on Rails

天大地大妈咪最大 提交于 2019-12-01 16:53:27
问题 I have a Project that belongs to User. In my user view I have a link to add a new project, with the parameter for the user I want to add the project to. <%= link_to 'Add new project', :controller => "project", :action => "new", :id => @user %> Url: /projects/new?id=62 Adding a project to a user works. The problem is when the validation fails while adding a new project and I do a render. def create @project = Project.new(params[:project]) if @project.save redirect_to :action => "show", :id =>

Keep params after render Ruby on Rails

不问归期 提交于 2019-12-01 16:32:15
I have a Project that belongs to User. In my user view I have a link to add a new project, with the parameter for the user I want to add the project to. <%= link_to 'Add new project', :controller => "project", :action => "new", :id => @user %> Url: /projects/new?id=62 Adding a project to a user works. The problem is when the validation fails while adding a new project and I do a render. def create @project = Project.new(params[:project]) if @project.save redirect_to :action => "show", :id => @project.id else render :action => "new" end end view: <%= form_for @project do |f| %> <%= f.label

DRYing up a helper: wrap form_for and access local form variable

北城余情 提交于 2019-12-01 13:04:45
问题 I am trying to DRY up a bunch of forms code that has a repeating set of fields appearing at the end of each form. I wrote a helper that wraps around the form_for rails helper. But I'm starting to get lost in all the different scopes that are flying around... My helper goes something like this: def simple_form_helper(record_or_name_or_array, *args, &proc) options = ... # overriding some options, not relevant form_for(record_or_name_or_array, *(args << options.merge(:option => "blah")) , &proc)

how to set default value of form_for select

雨燕双飞 提交于 2019-12-01 05:41:31
I would like to know how to set default value on form_for select. My code goes like this: <%= form_for(@user) do |f| %> . . . <div class="field"> <%= f.select(:user_group_id, options_for_select(@user_groups.collect {|p| [ p.name, p.id ] }, "Select Category")) %> </div> <%= end %> Obviously it would return all the values of the field user_group. On my edit page, I would like to set the default value to whatever value the user have in the user_group. Pls help You can pass a second option to options_for_select that indicates the selected value . options_for_select(@user_groups.collect { |p| [p

how to set default value of form_for select

只愿长相守 提交于 2019-12-01 03:06:13
问题 I would like to know how to set default value on form_for select. My code goes like this: <%= form_for(@user) do |f| %> . . . <div class="field"> <%= f.select(:user_group_id, options_for_select(@user_groups.collect {|p| [ p.name, p.id ] }, "Select Category")) %> </div> <%= end %> Obviously it would return all the values of the field user_group. On my edit page, I would like to set the default value to whatever value the user have in the user_group. Pls help 回答1: You can pass a second option

nested routes and form_for and models using has_one and belongs_to

纵饮孤独 提交于 2019-11-30 22:09:16
How to map out has_one model with nested routes and how to add a form_for for /localhost:3000/users/1/profile/new,html.erb following RESTful database? User has one Profile. Models class Profile < ActiveRecord::Base attr_accessible :name, :surname belongs_to :user end class User < ActiveRecord::Base attr_accessible :email, :email_confirmation, :password, :password_confirmation has_secure_password has_one :profile, dependent: :destroy end resources :users do resources :profiles (note: has_one profile) resources :progress_charts resources :calories_journals end views/profiles/new.html.erb <h1

Form_for with :multipart => true spits out

老子叫甜甜 提交于 2019-11-30 17:22:51
I am trying to add an Avatar Upload field to my Profile Page, but as soon as I add the :html => {:multipart => true} to it, it spits out an syntax error. <%= form_for(@user), :html => { :multipart => true } do |f| %> <%= render 'shared/error_messages', object: f.object %> <%= f.label :name %> <%= f.text_field :name %> <%= f.label :email %> <%= f.email_field :email %> <%= f.label :password %> <%= f.password_field :password %> <%= f.label :password_confirmation, "Confirmation" %> <%= f.password_field :password_confirmation %> <%= f.label :avatar %> <%= f.file_field :avatar %> <%= f.submit "Save