I've got an app that's in invite-only beta right now. Problem is, I can't get the invite system to work. :(
On my root page there's a login form (which works just fine), and I'm trying to add a "request invite" form on the same page. I started doing it by putting the form for InviteRequest (ActiveRecord) inside a partial, in the "views" folder for "InviteRequest". The app is definitely calling this partial, but I'm getting the following error:
NoMethodError in User_sessions#new
Showing app/views/invite_request/_new.html.erb where line #2 raised:
undefined method `invite_requests_path' for #<ActionView::Base:0x25b3248>
Extracted source (around line #2):
1: <% #invite_request = InviteRequest.new() %>
2: <% form_for #invite_request do |ir| %>
3: <%= ir.label :email %>
4: <%= ir.text_field :email %>
5: <% end %>
I also read through the "Multiple Models in a Form" section of my trusty copy of "Agile Web Development with Rails", about maybe doing this with a "fieldset" tag, but not sure if this is the right approach.
Thx.
Your form_for #invite_request is trying to figure out where the results from the form should be posted. It does this by looking at the routes and finding one that matches the resource and action needed. In your case I'm guessing you haven't set up routes for InviteRequest. You either need to set up routing for InviteRequest or specify the URL to be posted to in form_for.
form_for #invite_request, :url => { :controller => 'application', :action => 'request_invite' } do |form|
...
Related
Well, i'm new to rails, but not new to the rails way and i've got an error that i dont know how to fix it.
I've created the controller and than the view.
Controller:
class ReclamacoesController < ApplicationController
def new
#reclamacao = Reclamacao.new
end
end
and than, the view under Views>controllerName>new.html.erb.
<%= form_for #reclamacao do |f| %>
<%= f.text_field :titulo %>
<% end %>
The model Reclamacao exist.
I've created the resource routes for it too.
resources :reclamacoes
So, when i access /reclamacoes/new an exception is thrown.
NoMethodError in Reclamacoes#new
undefined method `reclamacaos_path' for #<#<Class:0x00000001fc0660>:0x00000001fba850>
Extracted source (around line #1):
<%= form_for #reclamacao do |f| %>
<%= f.text_field :titulo %>
<% end %>
Rails.root: /home/ubuntu/workspace/aqueleprojetoprivate/medicos
Application Trace | Framework Trace | Full Trace
app/views/reclamacoes/new.html.erb:1:in `_app_views_reclamacoes_new_html_erb___3194888715597102324_16164860'
the routes:
reclamacoes GET /reclamacoes(.:format) reclamacoes#index
POST /reclamacoes(.:format) reclamacoes#create
new_reclamaco GET /reclamacoes/new(.:format) reclamacoes#new
edit_reclamaco GET /reclamacoes/:id/edit(.:format) reclamacoes#edit
reclamaco GET /reclamacoes/:id(.:format) reclamacoes#show
PATCH /reclamacoes/:id(.:format) reclamacoes#update
PUT /reclamacoes/:id(.:format) reclamacoes#update
DELETE /reclamacoes/:id(.:format) reclamacoes#destroy
What is wrong?
Rails is trying to automatically guess plurals. The problem is that your resource is reclamacao which Rails is turning into reclamacaos plural. But you have named it as reclamacoes
I suggest either changing names or instruct Rails to use better plurals. Here's a relevant article: How do I override rails naming conventions?
Take a look at the output from rake routes. You will notice a spelling error
reclamacoes GET /reclamacoes(.:format) reclamacoes#index
POST /reclamacoes(.:format) reclamacoes#create
new_reclamaco GET /reclamacoes/new(.:format) reclamacoes#new
edit_reclamaco GET /reclamacoes/:id/edit(.:format) reclamacoes#edit
reclamaco GET /reclamacoes/:id(.:format) reclamacoes#show
PATCH /reclamacoes/:id(.:format) reclamacoes#update
PUT /reclamacoes/:id(.:format) reclamacoes#update
DELETE /reclamacoes/:id(.:format) reclamacoes#destroy
Based on the above output, the correct path name is reclamacoes path.
Rails emphasizes Convention over Configuration, and you have different spellings in your models, views and controllers.
I've already asked the question on the Redmine official website but I didn't get any answer, maybe I'll have more chance here.
I'm working on a project and I try to improve an existing plugin for Redmine by adding some features to it to allow the user to upload his Dropbox files in the Redmine documents with a simple form. Redmine already has this possibilty so I would like to use the controller and methods already defined in the Redmine source code.
I have the following code in one of my plugin views:
<% html_title "Reddrop - Sync" %>
<h2>Synchronisation page</h2>
<p>Please choose your file</p>
<%= form_tag({:controller => "documents", :action => "add_attachment", :id => #document}, :multipart => true) do %>
<%= file_field_tag 'attachments[dummy][file]', :id => nil, :multiple => true, :onchange => "addInputFiles(this)" %>
<%= submit_tag(value = "Sync this file with Redmine") %>
<% end %>
I'm calling the "documents" controller and the add_attachment method which are defined in the Redmine source code. When I submit my form I get the following error:
ActionController::RoutingError (No route matches {:controller=>"documents", :action=>"add_attachment", :id=>nil}):
Is it possible to call these controllers/methods through a plugin if they are defined in the Redmine source code?
If yes, maybe could you give some advice to how configure my routes?
See here :id => #document
#document is the variable that contains nil however this should contain some id (like 1,2 or whatever) of required record check it in your controller and once you will fix this issue sure this error will be resolved.
validate route format
rake | rails route
send the expected parameters and the correct namespace. If you already have a #document you could use the form_for.
`<% form_for(#document, url: {action:'add_attachment'} ) do %> `
I'm upgraded to rails 3.2.13 and I'm migrating an old app to run in the new environment (ruby1.9.3). The app ran fine with ruby192 and rails 3.0.0.
I was receiving this error when trying to create a new record (a firefighter)
wrong number of arguments (3 for 2)
And here was my code for my form
<%= form_for :fire_fighter, #fire_fighter, :url => { :action => "create" } do |f| %>
based on reading other posts, they recommend to remove "fire_fighter" but so it would look like this
<%= form_for :#fire_fighter, :url => { :action => "create" } do |f| %>
This did actually allow the page to render but when I tried to enter fill in the text fields and submit or create the record in the database I get an error message that is built into the app that says:
All of the fields are setup as strings.
Oh and obviously i had all this fields filled out before I hit submit. So now I'm just stuck.
Any help would be appreciated thanks.
Although this answer may change when you post your page source code and the rest of the form code, you are trying to create a symbol from an instance variable.
<%= form_for :#fire_fighter, :url => { :action => "create" } do |f| %>
Notice :#fire_fighter. It really should be #fire_fighter. The correct code should then be
<%= form_for #fire_fighter, :url => { :action => "create" } do |f| %>
The reason why you use an instance variable like #fire_fighter is because in your controller there should be something like
def new
#fire_fighter = FireFighter.new
end
that way, the form is directly grabbing the instance variable from the controller onto the form. Symbols don't transverse from controllers to views, but instance variables do, hence the use of #fire_fighter as the first argument in the form_for method.
Trying to route:
scope :shortcut do
resources :text_elems
end
Using basic scaffold with form partial
*_form.html.erb*
<%= form_for(#text_elem, :shortcut => #shortcut) do |f| %>
...
Problem is: When I call the edit action, the form html shows as:
<form ... action="/25/text_elems/25">
Note: The new action renders the form action correctly:
<form ... action="/home/text_elems">
So it appears that my :shortcut param is getting trumped by the :id param when form_for processes it's block. Now I am able to get the action to correctly route with the :shortcut param if I manually make the :url => {...} in the form_for block, but I would prefer to keep the code dry, plus I want to report this problem to rails if it is indeed a bug.
Can anyone else confirm this as a bug?
Actually, you can pass the values as a full hash, rather than trying to rely on the default to_param (which is what gets called if all you do is pass the #text_elem)
<%= form_for({:id => #text_elem.to_param, :shortcut => #shortcut}) do |f| %>
however, if this is actually a nested-resource, you could also do:
<%= form_for([#shortcut, #text_elem]) do |f| %>
I was having the same issues and none of the above answers helped.
The last answer on this page worked for me though...
https://rails.lighthouseapp.com/projects/8994/tickets/6736-problem-with-scoped-routes-and-form_for-helper
Ok I have posted a couple of things that had to do with my problem but I think I have it narrowed down. Here is where I am at:
I have my index.rhtml page inside of /views/main and the main_controller is set up correctly. I am attempting to make this page a dashboard of sorts so it needs to reference multiple other views to display their index.html.erb page. I will use 'proposals' as our example. I want to display the proposal views/proposals/index.html.erb page in the views/main/index.rhtml side bar. I have gathered that you do this through partials.
So...I created a file, /views/proposals/_index.html.erb that has the same code as views/proposals/index.html.erb.
Then in my views/main/index.rhtml file I have the following code:
<%= render :partial => #proposal %>
Now, I don't get an error message, simply nothing is displayed. I don't have anything referencing this (I don't think) in my routes.rb file and I suspect that is the problem.
Sorry for the redundancy on this question but I didn't even really know what I was asking. Hope this helps.
UPDATED:
When I put the <%= render :partial => "proposals/index" %> mentioned below I now get this error:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Extracted source (around line #1):
1: <% #proposals.each do |proposal| %>
2: <div id="proposalindex">
3: <%= link_to_unless_current h(proposal.name), proposal %><br/>
4: <p5>Added <%= time_ago_in_words(proposal.created_at) %> ago | </p5
This partial works within the proposals controller not not sure what this means.
<%= render :partial => "proposals/index" %>