473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

add an Account to a user

I am trying to add a Account to a user

but i am having a problem listing the accounts in the new user view


Users Controller
Expand|Select|Wrap|Line Numbers
  1. class UsersController < ApplicationController
  2.     before_filter :authenticate_user!
  3.  
  4.   def index
  5.     @user = User.all
  6.   end
  7.   def show
  8.     @user = User.find(params[:id])
  9.   end
  10.  
  11.   def new
  12.     @user = User.new
  13.     @account = Account.all # i think this line should give me all the accounts 
  14.   end
  15.  
  16.   def create
  17.     @user = User.new(params[:account])
  18.     if @user.save
  19.       flash[:success] = "User Created"
  20.       redirect_to @user
  21.     else
  22.       render 'new'
  23.     end
  24.   end
  25.  
  26.   def edit
  27.     @user = User.find(params[:id])
  28.   end
  29.  
  30.   def update
  31.     @user = User.find(params[:id])
  32.     if @user.update_attributes(params[:user])
  33.       flash[:success] = "User Updated"
  34.       redirect_to @account
  35.     else
  36.       render 'edit'
  37.     end
  38.   end
  39.  
  40.   def destroy
  41.     User.find(params[:id]).destroy
  42.     flash[:success] = "User Destroyed."
  43.     redirect_to user_path
  44.   end
  45.  
  46.  
  47. end
  48.  

View
Expand|Select|Wrap|Line Numbers
  1. <%= provide(:title, 'New User') %>
  2. <!-- Main content -->
  3. <section role="main" id="main">
  4.   <div class="with-padding">
  5.     <%= form_for(@user) do |f| %>
  6.     <table class="simple-table responsive-table">
  7.       <tbody>
  8.         <tr>
  9.           <td scope="row">
  10.           <%= f.label :email %>
  11.           </td>
  12.           <td><%= f.email_field :email %></td>
  13.         </tr>
  14.         <tr>
  15.           <td scope="row">
  16.           <%= f.label :username %>
  17.           </td>
  18.           <td><%= f.text_field :username %></td>
  19.         </tr>
  20.         <tr>
  21.           <td scope="row">
  22.           <%= f.label :password %>
  23.           </td>
  24.           <td><%= f.password_field :password %></td>
  25.         </tr>
  26.         <tr>
  27.           <td scope="row">
  28.           <%= f.label :password_confirmation %>
  29.           </td>
  30.           <td><%= f.password_field :password_confirmation %></td>
  31.         </tr>
  32.         <tr>
  33.           <td scope="row">
  34.           <%= f.label :first_name %>
  35.           </td>
  36.           <td><%= f.text_field :first_name %></td>
  37.         </tr>
  38.         <tr>
  39.           <td scope="row">
  40.           <%= f.label :last_name %>
  41.           </td>
  42.           <td><%= f.text_field :last_name %></td>
  43.         </tr>
  44.         <tr>
  45.           <td scope="row">
  46.            Account
  47.           </td>
  48.           <td>
  49.             This needs to be a Selct Box
  50.             <% @account.each |a| do %>
  51.             a.name
  52.             <% end %>
  53.           </td>
  54.         </tr>
  55.         <tr>
  56.  <tr>
  57.           <td colspan=2><%= f.submit "Create User" , :class => "button" %> &nbsp;&nbsp; <%= link_to "Cansel", users_path, :class => "button" %></td>
  58.         </tr>
  59.       </tbody>
  60.     </table>
  61.     <% end %>
  62.   </div>
  63. </section>
  64. <!-- End main content -->
  65.  

The Error that i am having
SyntaxError in Users#new

syntax error, unexpected keyword_do_block
'); @account.each |a| do
^
/Users/moiseszaragoza/Sites/sample/app/views/users/new.html.erb:66: syntax error, unexpected keyword_ensure, expecting $end
May 30 '12 #1
2 3742
Expand|Select|Wrap|Line Numbers
  1. <%= form_for(@user) do |f| %>
This line without "="

Expand|Select|Wrap|Line Numbers
  1. <% form_for(@user) do |f| %>
May 30 '12 #2
if i remove the the = i don't see the form at all
May 31 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: greg anderson | last post by:
On a ServiceProcessInstaller, I set the account, username, and password and I get the following exception. I have made sure that the account exists and has the "logon as a service" privilege. ...
4
by: Buggyman | last post by:
Hi, I'm having problems with good old error... Login failed for user 'NT Authority\Anonymous logon'. The default web page comes up fine, but when the user attempts to log in (which checks...
1
by: jerminator | last post by:
Ok I need some help. Up until Tuesday my application was working fine. It is an asp.net application written in VB. It is very data heavy and makes multiple calls to a database. The application...
4
by: Tim Sapp | last post by:
Folks, I am working on a .Net web site that connects to SQL Server 2000 on another box. The DBA has given me a Domain user account with rights to the database and table. I have confirmed with...
1
by: Cyron | last post by:
Hello Friends, I am using .NET 2.0 with Visual C#. I see that the Process.Start() method permits one to launch a new process as another user by specifying the additional username, password and...
1
by: Alex | last post by:
Hi everybody Is creating of the service, which must be ran under the "user account" something really tricky? I mean if in ServiceProcessInstaller properties I'm using account: Local System...
1
by: =?Utf-8?B?Qi5BaGxzdGVkdA==?= | last post by:
Hi all, This is something that I have been toying with for about a week now. What I want to achieve is Install a Service with Customised parameters (using InstallUtil.exe) for User Name. Example...
2
by: Jim in Arizona | last post by:
I made up a service that will move files from a folder on the machine that the service is running to a share on another machine. I use a try/catch incase an error is thrown and write that error to...
2
by: Lidia | last post by:
Anybody has any ideas?
1
by: Bassem | last post by:
Hello, I'm new to IIS, I was just using it for tests from my IDE. I'm totally confused about the difference between FTP account user name and password and regular windows account. Is each FTP...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.