Scott Ribe wrote in post #1147132:
> On May 26, 2014, at 8:00 AM, Fab Forestier <li...@ruby-forum.com> wrote:
>
>> But the in the methode ajouter how can I have something like
>> @myvariable=n or @myvariable=@defautrec[i] where I is the current line
>> of the table?
>
> <%= link_to controller: "pages", action: "ajouter", id: n %>

And then how can use the id in my methode?

> But your code is otherwise so messed up that I can't tell exactly what
> you're trying to do. What is the "do" at then end of the call to
> link_to? Is the <%end%> after </button> intended to be associated with
> it? Or is it supposed to be for the @defautrec.each, but is just in the
> wrong place?
>
> I suspect you're trying to wrap a button in a link, but that's not how
> HTML works, regardless of whether you're using Rails or not. Do you just
> want a button that acts like a link??? It that's the case, you want
> button_to:
>
> <http://stackoverflow.com/questions/12475299/ruby-on-rails-button-to-link-to>
> <http://stackoverflow.com/questions/6247491/rails-3-display-link-as-button>
>
> Anyway, you cannot just stick "do" at the end of a function call in
> order to start a loop. Remember, <%= %> just executes the Ruby code
> inside and inserts the result into the HTML, and this is not legitimate
> Ruby:
>
> link_to controller: "pages", action: "ajouter" do
>
> Or, for more clarity, since this is the way it would be parsed:
>
> link_to (controller: "pages", action: "ajouter" do)
>
I'am sorry I have forgotten some code :
in the controller : @defautrec= Defaut.all

In the view
 <% @defautrec.each do |n| %>
  <tr>
     <td><%= n.nomdefaut.nom_defaut%></td>
     <td><%= n.repere%></td>
     <td><%= link_to controller: "pages", action: "ajouter" do%><button, 
class="btn btn-mini btn-success">Ajouter</button><%end%>
     </td>
  </tr>
 <% end %>

I want a button which call a methode in my controller so I think your 
right I should replace link_to by button_to.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/d7f743004f8292e8147b3d392592a384%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to