form-for

Rails: form_for namespaced resource

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 11:31:37
I want to set up the CRUD for users, available just for administrators of my web application. So in routes.rb: namespace :admin do resources :user end which means this: admin_user_index GET /admin/user(.:format) admin/user#index POST /admin/user(.:format) admin/user#create new_admin_user GET /admin/user/new(.:format) admin/user#new edit_admin_user GET /admin/user/:id/edit(.:format) admin/user#edit admin_user GET /admin/user/:id(.:format) admin/user#show PUT /admin/user/:id(.:format) admin/user#update DELETE /admin/user/:id(.:format) admin/user#destroy Show, index work fine but edit and new don

form_for and scopes, rails 3

£可爱£侵袭症+ 提交于 2019-11-30 09:00:36
问题 I have a problem due to scopes and the form_for helper in rails 3. The routes - file looks like this: scope "(/:tab)" do resources :article end The form looks something like this: <%= form_for(@article) %> <%= f.label :title %> <%= f.text_field :title %> etc. <%end%> The tab - attribute is stored in params[:tab], as a string My problem is that this genereate wrong urls in the form. How could I get this to work ? The genreated url article_path(params[:tab], @article) works perfectly fine 回答1:

Rails: Using form_for multiple times (DOM ids)

拥有回忆 提交于 2019-11-30 08:16:13
I would like to use the form_for helper multiple times for the same model in the same page. But the input fields use the same ID attribute (in the HTML), so clicking on the label of a field in another form will select the same input in the first form. Is there a solution besides settings all attributes manually via :for => "title_#{item.id}" and :id => "title_#{item.id}"? Using Rails 3.0.9 You can use :namespace => 'some_unique_prefix' option. In contrast to :index , this will not change the value used in the name attribute. It's also possible to use an array, e.g. when you have nested forms

STI and form_for problem

一世执手 提交于 2019-11-30 01:58:37
I am using Single Table Inheritance for managing different types of projects. Models: class Project < ActiveRecord::Base end class SiteDesign < Project end class TechDesign < Project end Edit action from projects_controller: def edit @project = Project.find(params[:id]) end View edit.html.erb: <% form_for(@project, :url => {:controller => "projects",:action => "update"}) do |f| %> ... <%= submit_tag 'Update' %> <% end %> Update action of projects_controller: def update @project = Project.find(params[:id]) respond_to do |format| if @project.update_attributes(params[:project]) @project.type =

Form_for with :multipart => true spits out

南笙酒味 提交于 2019-11-30 00:55:20
问题 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

Custom text for rails form_for label

∥☆過路亽.° 提交于 2019-11-30 00:12:02
I want to display a label in form_for : <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> </div> This generates the label "Name", but I want it to be "Your Name". How can I change it? The second parameter to label helper will allow you to set custom text. <%= f.label :name, 'Your Name' %> Use Ruby on Rails Documentation to look up helper methods. You can specify custom label text via i18n. In config/locales/en.yml , and assuming your user model is named user , you can add the following: helpers: label: user: name: Your Name This will allow you to keep using <%= f.label

Rails: Using form_for multiple times (DOM ids)

我只是一个虾纸丫 提交于 2019-11-29 10:58:58
问题 I would like to use the form_for helper multiple times for the same model in the same page. But the input fields use the same ID attribute (in the HTML), so clicking on the label of a field in another form will select the same input in the first form. Is there a solution besides settings all attributes manually via :for => "title_#{item.id}" and :id => "title_#{item.id}"? Using Rails 3.0.9 回答1: You can use :namespace => 'some_unique_prefix' option. In contrast to :index , this will not change

Difference between form_for and form_tag?

旧时模样 提交于 2019-11-29 06:15:10
I used this gem in my application, but I'm not sure the difference between the different implementation options for the gem: form_for form_tag with block form_tag without block Can anyone clarify? I understand that form_for is used when you wish to interact with a model, but what about the other two? The differences are subtle, but important. form_for is a more advanced tool that yields an object you use to generate your form elements: <% form_for(@foo) do |form| %> <%= form.text_field(:bar) %> <% end %> The form_tag method is much more primitive and just emits a tag. If you want to put things

RoR differences between :url, :action, :method in form_for

拈花ヽ惹草 提交于 2019-11-28 17:57:00
There might be answers in documentation, but i don't seem to find good answers. So among the three :url, :action, :method, what are their differences when used in form_for in Rails? Dipak Panchal Difference between :url , :action and :method :url If you want to submit your form for any particular controller, any particular action and want to pass some extra parameter (use action that define in controller that you pass on controller ) for example <%= form_for @post, :url => {:controller => "your-controller-name", :action => "your-action-name"} do |f| %> In the above code the form is submitted

When using shallow routes, different routes require different form_for arguments

别等时光非礼了梦想. 提交于 2019-11-28 17:46:46
I'm using Simple Form here, but this is an issue with normal Rails forms, too. When using shallow routes, form_for needs different arguments depending in what context it's used. Example: For editing ( http://localhost:3000/notes/2/edit ), _form.html.erb needs to have simple_form_for(@note) . But for creating a new note ( http://localhost:3000/customers/2/notes/new ) _form.html.erb needs simple_form_for([@customer, @note]) . If either receives the wrong arguments, I'll get a method not found error. What's the best way to deal with this? I could make two separate forms, but that seems messy. I