0

I want to pass some parameters with link_to method to create method, so that the form will shown prefilled to a user.

I wrote this code to pass the parameters,

<%= link_to "Buy", new_transaction_url(:friend_id => @friend.id, :t_type => 2) %>

And in transactions_controller's new method, I have:

@transaction = Transaction.new
@transaction.t_type = params[:t_type]

It didn't work as well.

That would be great if you can help me.

Thanks.

CanCeylan
  • 2,890
  • 8
  • 41
  • 51

2 Answers2

1

Try change params[:t_type] to params[:transaction][:t_type].

Thanh
  • 8,219
  • 5
  • 33
  • 56
0

Usually new_transaction_url would call the #new action in your controller, not the #create action. Watch your log file while you do it to see exactly what controller action is being called and what parameters are being passed.

Philip Hallstrom
  • 19,673
  • 2
  • 42
  • 46
  • I'm so sorry, I made a mistake, I wrote this code inside the new method. And it's not working. – CanCeylan Nov 15 '12 at 03:12
  • Then we need to know what exactly isn't working? What's the log file say is being passed? – Philip Hallstrom Nov 15 '12 at 03:20
  • It doesn't show any errors: Started GET "/transactions/new" for 127.0.0.1 at 2012-11-15 04:23:46 +0100 Processing by TransactionsController#new as HTML User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 Friend Load (0.2ms) SELECT "friends".* FROM "friends" WHERE "friends"."user_id" = 1 – CanCeylan Nov 15 '12 at 03:23
  • Ok. So what isn't happening that you expect to happen? – Philip Hallstrom Nov 15 '12 at 03:27