I can't seem to find an answer to what should be simple. I'm using Serve, which runs on a WEBRick server. I'd like to be able to grab the current page's URL. How would I do that?
Since Serve uses Rack under the hood, try this in a view:
<%= request.url %>
Related
My logo loads on my RoR application locally. When I login however, it fails to load each time. If however, I redirect to the same page, it will load again. I'm not sure I understand what the problem is.
The link to my project can be found here https://github.com/dlyons8/family-and-community.
The logo cannot be loaded because your path is being changed after successfully logging in as an user. The Sessions controller will be redirect the user to /users/:user_id.
The affected src attribute in the <img> tag contains "logo.png" so the browser tries to fetch /users/logo.png which will not succeed.
You have two options:
1) Change your logo as an asset. This is commonly used pattern for resources and helps a lot later in deployment when you change the logo for example. Move logo.png to app/assets/images and in the app/views/layouts/application.html.erb use the image_tag helper:
<%= image_tag 'logo.png', alt: 'Logo' %>
In this way, you will always get the absolute path of your logo (/assets/logo.png) and don't have to worry about where is the user actually.
2) Change the path in the <img> tag to absolute path of the logo (/logo.png) and it will try to fetch the correct file.
The 2) solution would be easier, however I strongly recommend you to get in touch with the Asset Pipeline in Rails because it really helps a lot in handling static assets for your webpage.
Also, if you encounter a non-loading asset, always check the browser's console. In Google Chrome, you can reach it by simply pressing F12 and switching to Console tab, there will be a red error message about what resource could not be loaded and why. The displayed full URL is often helps in these sneaky problems.
you need to place the images under assets/images folder
<%= image_tag ("/assets/ruby.jpeg") %>
change assets compile to true default it is false in config/environments/development.rb
config.assets.compile = true
I use rails 3.2.9 in webrick. My site seems to vulnerable to CSRF.
I have already added <%= csrf_meta_tags %> to the layout file..
And added the Protect_from_forgery in my application controller..
but when i try to make a Post request from a form in another domain, it's possible.. My site still seems to be vulnerable to CSRF..
I'm struck, wondering how to proceed! Pls help me out
I've added modernizr-rails to my rails project, and it seems to load fine (I can access Modernizr in a debug javascript console). According to the documentation, I added the include tag to the html head section like so:
<%= javascript_include_tag :modernizr %>
But it seems to load after my application javascript file (app/assets/javascripts/app.js), causing any reference to it to fail.
It's a mostly fresh new rails project, is there anything I'm missing? Or am I meant to wait for the document loaded event before calling Modernizr anyway?
Oops, yes there was something missing. I had put the javascript_include_tag :modernizr code in my template, rather than the application layout (app/views/layouts/application), which defines the html head for all templates in the app.
I implemented the wicked gem and it works quite nice. Using the rails cast got it to go between parts of the various steps using link_tos. this is great but it doesn't obviously do the submit_tag like when you click "save document" at the bottom of each page... I would like something to happen to call the update method in the controller with the data from that form but I am not sure how to do this with the standard link_to and previous_wizard_path and next_wizard_path helpers, as those do not call the update but the show it seems.
So not sure, is the link_to to navigate between steps not the preferred way if data has to be saved from each form step in between?
well, usually, you use a form with submit button for each wizard step - just as in the railscast.
the use of link_to is only presented as a way for skipping steps.
I am having problems setting rjs up and I don't know the right way to code this for rails 2.3.14
Are they (link_to_remote and link_to with :remote > true) the same or do they reflect rails versions or are they in fact different?
I am using prototype, as required by my company (so jquery is not an option).
I also see that there is link_to_function so I am really not sure what the right approach is!
link_to :remote => true is a Rails 3 convention and doesn't work in Rails 2. Since you are using Rails 2.3 you'll want to use link_to_remote for ajax calls.
link_to_function is used for when you want some javascript to run when a link is clicked and not necessarily an ajax call to the server. Stuff like showing/hiding elements on a page.