I'm using Rails 3.1 here, and I've got the following code in my view:
<%= link_to "again!", main_pick_path,{:method => :post, :var => #var} %>
The idea is to create a link (not a button) which, when clicked, calls the pick action of the main controller, passing the value of #var in params via a POST request.
This code generates the following HTML in my browser:
a href="/main/pick" data-method="post" rel="nofollow" var="foo">again!</a>
However when I click the link I am still sending a GET request. Is this a limitation of my browser, Chrome? From a design standpoint, should I be using a GET request instead and putting the variable into the URL? Are hyperlinks simply incapable of using the POST method? Is there life after death?
Thanks in advance
You can only do this with AJAX or firing a FORM. The tag A cant do a POST "alone".
Related
I'm trying to use the erb template on my angular templates folder, but the functionality is limited, for example,
The <% link_to
is working
but devise methods or even raw('sdmdslkc') pops an error that the method is not found.
for example
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
work on views but not in angular templates (says destroy_user_session_path method not found)
Whats missing ? is it fixable?
let me see if i understand, u have some template with some tags that belongs to another language that is not angular, html, or js. if so then it is not fixable because angular sends an ajax to bring that html file and injects it to your page, alot after any server has rendered any part of the page.
my suggestion for a work around is to try and tell angular to take a server page, say it was with asp.net and i would like some server tags i would tell angular that the template is somepage.aspx while making sure that my page evetually returns plain html.
I application.html.erb I add <%= yield %>. I want to show registration page (/users/sign_up) with header and footer in application.html.erb. As I understand contant from /device/registration/new.html.erb must contain in yield, but I get registration page withot templates(header and footer).
How I could show registration form in yiled?
I use RoR 3.2.12. Sorry for my English. Thanks.
If you get the registration page without the layout, then chances are you have a :layout => false triggered somewhere upstream.
I'm sure this is pretty basic, but I'm somewhat new to rails and struggling to find a solution via search.
I'm implementing a message model to enable private messaging on a forum. I have the models resource nested within a users resource.
Currently the model works, but I want to enable a user to reply to a private message directly on the message show page. I.e users/1/messages/16 instead of users/1/messages/new. Currently this is the default route for 'update' within the MessagesController. Is there anyway to make the form on this page hit the 'create' action within the controller, instead of the 'update'?
Thanks.
Sure, I would try something like this:
On your show page just add a new form.
<%= form_for :message, :url => new_user_message_path do |f| %>
...
<% end %>
You can check the routes of your application using this command:
bundle exec rake routes
I suggest you to read the rails guide: http://guides.rubyonrails.org/
I have watched railscasts about unobtrusive javascript and read numerous tutorials, but two things about unobtrusive javascript in Rails3 still confuses me:
End-point for simple javascript (hiding some elements, adding CSS class, ...)
Passing arguments to JS
Let me clarify this with sample code. I want to make a link which fades out some element with id "sample":
link_to 'Fade sample', url, :remote => true
What should be the url so it can execute JS? Should it be new action in controller named for example 'javascript' so it can access JS in javascript.js.erb which contains:
$('#sample').fadeOut();
Also, second question about ujs is related with passing arguments to JS (timeout, for this example). I can write:
link_to 'Fade sample', url, :data-timeout => 1500, :remote => true
but don't know how to access data-timeout in javascript.
I am using Rails 3.0.5, JQuery 1.5.2 and jquery-ujs.
I would try to answer one by one.
url in link_to. It would be a url hash for any resource in the application. Lets suppose you have specified resources :foos in the routes.rb, it will create 6 urls for CRUD operation. You can pass these to the urls by the methods like new_foo_url, foo_url(#foo) or foos_url. Even you can pass a hash manually like {:controller=>:foos_controller, :action=>:index}, also you can pass multiple parameters to the hash like {:controller=>:foos_controller, :action=>:index, :param1=>"value1", :param2=>"value2"}. Also you can pass strings urls like foos/new, foos/1 etc
You can access custom tag attributes with jQuery very easily. for example you want to access anchor with id="link", you can $('#link').attr("data-timeout"). If you don't know what exactly the id is, but you know it have an attribute you can call $("a[data-timeout]").first().attr('data-timeout')
Hey,
I'm pretty new to rails and for learning effect, I try to implement my own authorization system.
Right now I'm having a Page Controller to control some static pages and nothing more, and a Session Controller where I plan to implement most of the authorization process.
My problem is, I have no clue how to get my partial to use the sessions-controller, when I add it to one of the static pages controlled by the pages controller.
It stated out with this http://ruby.railstutorial.org/chapters/sign-in-sign-out#top but i don't want it on an extra page.
so I tried setting the routes and I got an exception "no path found for '/'" as soon as I deleted "resources :sessions" it worked fine again.
my partial looks like this:
<%= form_for(User.new) do |f| %>
<%= f.submit "Login" %>
<% end %>
there's also a div class="action" block around the submit but can't find out how to escape it
this is included into my home via
<%= render 'sessions/new' %>
Thanks for your help
edit my solution:
I added to routes.rb:
resources :sessions
Furthermore I changed form_for(#user) to
<%= form_for(:session, url => sessions_path)
so this works.
I Highly recommed that you look at the railscast http://railscasts.com/episodes/250-authentication-from-scratch , it will give you an idea how to create authentication without forgetting some important steps.
Then you can use the gem devise which is an excellent authentication gem.
Have you tried putting your functions and everything for authentication within a Session Helpers file? Then, in your Application Controller if you add "include SessionsHelper" this should give you access to all the helper functions from Session that you should need